mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-15 13:45:55 +08:00
feat: 支持使用环境变量 SUB_STORE_PRODUCE_CRON
在后台定时处理订阅, 格式为 0 */2 * * *,sub,a;0 */3 * * *,col,b
This commit is contained in:
parent
1b4c046b75
commit
b1618c3803
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.16.59",
|
"version": "2.16.60",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -2,7 +2,7 @@ import express from '@/vendor/express';
|
|||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
import migrate from '@/utils/migration';
|
import migrate from '@/utils/migration';
|
||||||
import download from '@/utils/download';
|
import download from '@/utils/download';
|
||||||
import { syncArtifacts } from '@/restful/sync';
|
import { syncArtifacts, produceArtifact } from '@/restful/sync';
|
||||||
import { gistBackupAction } from '@/restful/miscs';
|
import { gistBackupAction } from '@/restful/miscs';
|
||||||
import { TOKENS_KEY } from '@/constants';
|
import { TOKENS_KEY } from '@/constants';
|
||||||
|
|
||||||
@ -75,6 +75,39 @@ export default function serve() {
|
|||||||
// 'Asia/Shanghai' // timeZone
|
// 'Asia/Shanghai' // timeZone
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// 格式: 0 */2 * * *,sub,a;0 */3 * * *,col,b
|
||||||
|
// 每 2 小时处理一次单条订阅 a, 每 3 小时处理一次组合订阅 b
|
||||||
|
const produce_cron = eval('process.env.SUB_STORE_PRODUCE_CRON');
|
||||||
|
if (produce_cron) {
|
||||||
|
$.info(`[PRODUCE CRON] ${produce_cron} enabled`);
|
||||||
|
const { CronJob } = eval(`require("cron")`);
|
||||||
|
produce_cron.split(/\s*;\s*/).map((item) => {
|
||||||
|
const [cron, type, name] = item.split(/\s*,\s*/);
|
||||||
|
new CronJob(
|
||||||
|
cron.trim(),
|
||||||
|
async function () {
|
||||||
|
try {
|
||||||
|
$.info(
|
||||||
|
`[PRODUCE CRON] ${type} ${name} ${cron} started`,
|
||||||
|
);
|
||||||
|
await produceArtifact({ type, name });
|
||||||
|
$.info(
|
||||||
|
`[PRODUCE CRON] ${type} ${name} ${cron} finished`,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
$.error(
|
||||||
|
`[PRODUCE CRON] ${type} ${name} ${cron} error: ${
|
||||||
|
e.message ?? e
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, // onTick
|
||||||
|
null, // onComplete
|
||||||
|
true, // start
|
||||||
|
// 'Asia/Shanghai' // timeZone
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
const backend_download_cron = eval(
|
const backend_download_cron = eval(
|
||||||
'process.env.SUB_STORE_BACKEND_DOWNLOAD_CRON',
|
'process.env.SUB_STORE_BACKEND_DOWNLOAD_CRON',
|
||||||
);
|
);
|
||||||
|
@ -43,7 +43,7 @@ async function produceArtifact({
|
|||||||
}) {
|
}) {
|
||||||
platform = platform || 'JSON';
|
platform = platform || 'JSON';
|
||||||
|
|
||||||
if (type === 'subscription') {
|
if (['subscription', 'sub'].includes(type)) {
|
||||||
let sub;
|
let sub;
|
||||||
if (name) {
|
if (name) {
|
||||||
const allSubs = $.read(SUBS_KEY);
|
const allSubs = $.read(SUBS_KEY);
|
||||||
@ -190,7 +190,7 @@ async function produceArtifact({
|
|||||||
}
|
}
|
||||||
// produce
|
// produce
|
||||||
return ProxyUtils.produce(proxies, platform, produceType, produceOpts);
|
return ProxyUtils.produce(proxies, platform, produceType, produceOpts);
|
||||||
} else if (type === 'collection') {
|
} else if (['collection', 'col'].includes(type)) {
|
||||||
const allSubs = $.read(SUBS_KEY);
|
const allSubs = $.read(SUBS_KEY);
|
||||||
const allCols = $.read(COLLECTIONS_KEY);
|
const allCols = $.read(COLLECTIONS_KEY);
|
||||||
const collection = findByName(allCols, name);
|
const collection = findByName(allCols, name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user