@kingsworld/plugin-cron 3.0.1-next.e1b3c15 → 3.0.2-next.69cca0b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -31
- package/README.md +23 -15
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +58 -35
- package/dist/cjs/lib/CronTaskHandler.cjs +6 -26
- package/dist/cjs/lib/CronTaskHandler.cjs.map +1 -1
- package/dist/cjs/lib/structures/CronTask.cjs.map +1 -1
- package/dist/cjs/lib/structures/CronTaskStore.cjs +81 -20
- package/dist/cjs/lib/structures/CronTaskStore.cjs.map +1 -1
- package/dist/cjs/lib/utils/normalizePattern.cjs +45 -0
- package/dist/cjs/lib/utils/normalizePattern.cjs.map +1 -0
- package/dist/cjs/register.cjs +4 -4
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/esm/index.d.mts +58 -35
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/CronTaskHandler.mjs +5 -25
- package/dist/esm/lib/CronTaskHandler.mjs.map +1 -1
- package/dist/esm/lib/structures/CronTask.mjs.map +1 -1
- package/dist/esm/lib/structures/CronTaskStore.mjs +81 -20
- package/dist/esm/lib/structures/CronTaskStore.mjs.map +1 -1
- package/dist/esm/lib/utils/normalizePattern.mjs +42 -0
- package/dist/esm/lib/utils/normalizePattern.mjs.map +1 -0
- package/dist/esm/register.mjs +4 -4
- package/dist/esm/register.mjs.map +1 -1
- package/package.json +10 -10
@@ -1,8 +1,9 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var pieces = require('@sapphire/pieces');
|
4
|
-
var
|
4
|
+
var croner = require('croner');
|
5
5
|
var CronTask_cjs = require('./CronTask.cjs');
|
6
|
+
var normalizePattern_cjs = require('../utils/normalizePattern.cjs');
|
6
7
|
|
7
8
|
var __defProp = Object.defineProperty;
|
8
9
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
@@ -11,58 +12,118 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
11
12
|
super(CronTask_cjs.CronTask, { name: "cron-tasks" });
|
12
13
|
}
|
13
14
|
/**
|
14
|
-
* Loops over all tasks and
|
15
|
-
*
|
15
|
+
* Loops over all tasks and pauses those that are running.
|
16
|
+
*
|
17
|
+
* @remarks
|
18
|
+
* This method will only pause tasks that:
|
19
|
+
* - Are enabled
|
20
|
+
* - Are currently running
|
21
|
+
* - Have not been permanently stopped
|
22
|
+
*
|
16
23
|
* @returns CronTaskStore
|
17
24
|
*/
|
18
|
-
|
25
|
+
pauseAll() {
|
19
26
|
for (const task of this.values()) {
|
20
|
-
if (!task.enabled) continue;
|
21
|
-
task.job.
|
27
|
+
if (!task.enabled || !task.job.isRunning()) continue;
|
28
|
+
task.job.pause();
|
22
29
|
}
|
23
|
-
pieces.Store.logger?.(`[STORE => ${this.name}] [
|
30
|
+
pieces.Store.logger?.(`[STORE => ${this.name}] [PAUSE] Paused all cronjob tasks.`);
|
31
|
+
return this;
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Loops over all tasks and resumes those that are paused.
|
35
|
+
*
|
36
|
+
* @remarks
|
37
|
+
* This method will only resume tasks that:
|
38
|
+
* - Are enabled
|
39
|
+
* - Are not currently running
|
40
|
+
* - Have not been permanently stopped
|
41
|
+
*
|
42
|
+
* @returns CronTaskStore
|
43
|
+
*/
|
44
|
+
resumeAll() {
|
45
|
+
for (const task of this.values()) {
|
46
|
+
if (!task.enabled || task.job.isRunning() || task.job.isStopped()) continue;
|
47
|
+
task.job.resume();
|
48
|
+
}
|
49
|
+
pieces.Store.logger?.(`[STORE => ${this.name}] [RESUME] Resumed all cronjob tasks.`);
|
24
50
|
return this;
|
25
51
|
}
|
26
52
|
/**
|
27
53
|
* Loops over all tasks and stops those that are running.
|
54
|
+
*
|
55
|
+
* @remarks
|
56
|
+
* This method will only stop tasks that:
|
57
|
+
* - Are enabled
|
58
|
+
* - Have not been permanently stopped
|
59
|
+
*
|
60
|
+
* ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!
|
61
|
+
*
|
28
62
|
* @returns CronTaskStore
|
29
63
|
*/
|
30
64
|
stopAll() {
|
31
65
|
for (const task of this.values()) {
|
32
|
-
if (!task.job.
|
66
|
+
if (!task.enabled || task.job.isStopped()) continue;
|
33
67
|
task.job.stop();
|
34
68
|
}
|
35
69
|
pieces.Store.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);
|
36
70
|
return this;
|
37
71
|
}
|
38
72
|
set(key, value) {
|
39
|
-
const { options } = value;
|
40
|
-
const { sentry, defaultTimezone } = this.container.
|
41
|
-
|
73
|
+
const { pattern, timezone, protect, ...options } = value.options;
|
74
|
+
const { sentry, defaultTimezone } = this.container.cronTasks;
|
75
|
+
if (this.has(key)) {
|
76
|
+
pieces.Store.logger?.(`[STORE => ${this.name}] [SET] Stopping existing cronjob task before creating a new one.`);
|
77
|
+
this.get(key)?.job.stop();
|
78
|
+
}
|
79
|
+
const timeZone = timezone ?? defaultTimezone;
|
42
80
|
try {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
81
|
+
pieces.Store.logger?.(
|
82
|
+
`[STORE => ${this.name}] [SET] Creating cronjob for ${key} with '${pattern}' as the pattern and '${timeZone}' for the timezone`
|
83
|
+
);
|
84
|
+
value.job = new croner.Cron(
|
85
|
+
pattern,
|
86
|
+
{
|
87
|
+
name: key,
|
88
|
+
timezone: timeZone,
|
89
|
+
paused: true,
|
90
|
+
// we start the job manually once the client is ready
|
91
|
+
protect: value.protect ? (job) => void value.protect(job) : protect,
|
92
|
+
catch: /* @__PURE__ */ __name((error) => {
|
93
|
+
value.error("Encountered an error while running the cron job", error);
|
94
|
+
if (sentry) sentry.captureException(error);
|
95
|
+
void value.catch?.(error, value.job);
|
96
|
+
}, "catch"),
|
97
|
+
...options
|
98
|
+
},
|
99
|
+
() => {
|
100
|
+
if (sentry && typeof pattern === "string" && !pattern.includes(":")) {
|
101
|
+
return sentry.withMonitor(key, () => void value.run.bind(value)(), {
|
102
|
+
schedule: { type: "crontab", value: pattern },
|
103
|
+
timezone: timeZone ? normalizePattern_cjs.normalizePattern(timeZone) : void 0
|
104
|
+
});
|
105
|
+
}
|
106
|
+
return value.run.bind(value)();
|
107
|
+
}
|
108
|
+
);
|
50
109
|
} catch (error) {
|
51
110
|
value.error("Encountered an error while creating the cron job", error);
|
52
111
|
void value.unload();
|
53
112
|
}
|
54
113
|
return super.set(key, value);
|
55
114
|
}
|
115
|
+
/**
|
116
|
+
* Deletes a task from the store and stops it if it's running.
|
117
|
+
*/
|
56
118
|
delete(key) {
|
57
119
|
const task = this.get(key);
|
58
|
-
if (task
|
120
|
+
if (task && !task.job.isStopped()) {
|
59
121
|
task.job.stop();
|
60
122
|
}
|
61
123
|
return super.delete(key);
|
62
124
|
}
|
63
125
|
/**
|
64
126
|
* Stops all running cron jobs and clears the store.
|
65
|
-
* @returns void
|
66
127
|
*/
|
67
128
|
clear() {
|
68
129
|
this.stopAll();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":["Store","CronTask","
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":["Store","CronTask","Cron","normalizePattern"],"mappings":";;;;;;;;;AAKO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,YAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAMC,qBAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA;AAAA;AACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAW,GAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAA,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} from './CronTask';\nimport { normalizePattern } from '../utils/normalizePattern';\n\nexport class CronTaskStore extends Store<CronTask, 'cron-tasks'> {\n\tpublic constructor() {\n\t\tsuper(CronTask, { name: 'cron-tasks' });\n\t}\n\n\t/**\n\t * Loops over all tasks and pauses those that are running.\n\t *\n\t * @remarks\n\t * This method will only pause tasks that:\n\t * - Are enabled\n\t * - Are currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic pauseAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || !task.job.isRunning()) continue;\n\t\t\ttask.job.pause();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [PAUSE] Paused all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and resumes those that are paused.\n\t *\n\t * @remarks\n\t * This method will only resume tasks that:\n\t * - Are enabled\n\t * - Are not currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic resumeAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isRunning() || task.job.isStopped()) continue;\n\t\t\ttask.job.resume();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [RESUME] Resumed all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and stops those that are running.\n\t *\n\t * @remarks\n\t * This method will only stop tasks that:\n\t * - Are enabled\n\t * - Have not been permanently stopped\n\t *\n\t * ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isStopped()) continue;\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\tpublic override set(key: string, value: CronTask): this {\n\t\tconst { pattern, timezone, protect, ...options } = value.options;\n\t\tconst { sentry, defaultTimezone } = this.container.cronTasks;\n\n\t\t// if a task with the same key already exists, stop it before creating a new one\n\t\tif (this.has(key)) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [SET] Stopping existing cronjob task before creating a new one.`);\n\t\t\tthis.get(key)?.job.stop();\n\t\t}\n\n\t\tconst timeZone = timezone ?? defaultTimezone;\n\n\t\ttry {\n\t\t\tStore.logger?.(\n\t\t\t\t`[STORE => ${this.name}] [SET] Creating cronjob for ${key} with '${pattern}' as the pattern and '${timeZone}' for the timezone`\n\t\t\t);\n\n\t\t\tvalue.job = new Cron(\n\t\t\t\tpattern,\n\t\t\t\t{\n\t\t\t\t\tname: key,\n\t\t\t\t\ttimezone: timeZone,\n\t\t\t\t\tpaused: true, // we start the job manually once the client is ready\n\t\t\t\t\tprotect: value.protect ? (job) => void value.protect!(job) : protect,\n\t\t\t\t\tcatch: (error) => {\n\t\t\t\t\t\tvalue.error('Encountered an error while running the cron job', error);\n\t\t\t\t\t\tif (sentry) sentry.captureException(error);\n\t\t\t\t\t\tvoid value.catch?.(error, value.job);\n\t\t\t\t\t},\n\t\t\t\t\t...options\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\t// we only want to monitor cron patterns and not single-use tasks that croner supports\n\t\t\t\t\tif (sentry && typeof pattern === 'string' && !pattern.includes(':')) {\n\t\t\t\t\t\treturn sentry.withMonitor(key, () => void value.run.bind(value)(), {\n\t\t\t\t\t\t\tschedule: { type: 'crontab', value: pattern },\n\t\t\t\t\t\t\ttimezone: timeZone ? normalizePattern(timeZone) : undefined\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value.run.bind(value)();\n\t\t\t\t}\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tvalue.error('Encountered an error while creating the cron job', error);\n\t\t\tvoid value.unload();\n\t\t}\n\n\t\treturn super.set(key, value);\n\t}\n\n\t/**\n\t * Deletes a task from the store and stops it if it's running.\n\t */\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task && !task.job.isStopped()) {\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Stops all running cron jobs and clears the store.\n\t */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
5
|
+
|
6
|
+
// src/lib/utils/normalizePattern.ts
|
7
|
+
var predefined = {
|
8
|
+
"@annually": "0 0 1 1 *",
|
9
|
+
"@yearly": "0 0 1 1 *",
|
10
|
+
"@monthly": "0 0 1 * *",
|
11
|
+
"@weekly": "0 0 * * 0",
|
12
|
+
"@daily": "0 0 * * *",
|
13
|
+
"@hourly": "0 * * * *"
|
14
|
+
};
|
15
|
+
var cronTokens = {
|
16
|
+
jan: 1,
|
17
|
+
feb: 2,
|
18
|
+
mar: 3,
|
19
|
+
apr: 4,
|
20
|
+
may: 5,
|
21
|
+
jun: 6,
|
22
|
+
jul: 7,
|
23
|
+
aug: 8,
|
24
|
+
sep: 9,
|
25
|
+
oct: 10,
|
26
|
+
nov: 11,
|
27
|
+
dec: 12,
|
28
|
+
sun: 0,
|
29
|
+
mon: 1,
|
30
|
+
tue: 2,
|
31
|
+
wed: 3,
|
32
|
+
thu: 4,
|
33
|
+
fri: 5,
|
34
|
+
sat: 6
|
35
|
+
};
|
36
|
+
var tokensRegex = new RegExp(Object.keys(cronTokens).join("|"), "g");
|
37
|
+
function normalizePattern(pattern) {
|
38
|
+
if (Reflect.has(predefined, pattern)) return Reflect.get(predefined, pattern);
|
39
|
+
return pattern.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));
|
40
|
+
}
|
41
|
+
__name(normalizePattern, "normalizePattern");
|
42
|
+
|
43
|
+
exports.normalizePattern = normalizePattern;
|
44
|
+
//# sourceMappingURL=normalizePattern.cjs.map
|
45
|
+
//# sourceMappingURL=normalizePattern.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/normalizePattern.ts"],"names":[],"mappings":";;;;;;AAMA,IAAM,UAAa,GAAA;AAAA,EAClB,WAAa,EAAA,WAAA;AAAA,EACb,SAAW,EAAA,WAAA;AAAA,EACX,UAAY,EAAA,WAAA;AAAA,EACZ,SAAW,EAAA,WAAA;AAAA,EACX,QAAU,EAAA,WAAA;AAAA,EACV,SAAW,EAAA;AACZ,CAAA;AAEA,IAAM,UAAqC,GAAA;AAAA,EAC1C,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,EAAA;AAAA,EACL,GAAK,EAAA,EAAA;AAAA,EACL,GAAK,EAAA,EAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA;AACN,CAAA;AAEA,IAAM,WAAA,GAAc,IAAI,MAAA,CAAO,MAAO,CAAA,IAAA,CAAK,UAAU,CAAE,CAAA,IAAA,CAAK,GAAG,CAAA,EAAG,GAAG,CAAA;AAE9D,SAAS,iBAAiB,OAAyB,EAAA;AACzD,EAAI,IAAA,OAAA,CAAQ,IAAI,UAAY,EAAA,OAAO,GAAU,OAAA,OAAA,CAAQ,GAAI,CAAA,UAAA,EAAY,OAAO,CAAA;AAC5E,EAAO,OAAA,OAAA,CAAQ,OAAQ,CAAA,WAAA,EAAa,CAAC,KAAA,KAAU,MAAO,CAAA,OAAA,CAAQ,GAAI,CAAA,UAAA,EAAY,KAAK,CAAC,CAAC,CAAA;AACtF;AAHgB,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA","file":"normalizePattern.cjs","sourcesContent":["/*\n * Credits to Sapphire for this\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/constants.ts#L26-L57\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/Cron.ts#L91\n */\n\nconst predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nconst cronTokens: Record<string, number> = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nconst tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n\nexport function normalizePattern(pattern: string): string {\n\tif (Reflect.has(predefined, pattern)) return Reflect.get(predefined, pattern);\n\treturn pattern.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n}\n"]}
|
package/dist/cjs/register.cjs
CHANGED
@@ -7,17 +7,17 @@ var __defProp = Object.defineProperty;
|
|
7
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
8
8
|
var _CronTaskPlugin = class _CronTaskPlugin extends framework.Plugin {
|
9
9
|
static [framework.preGenericsInitialization](options) {
|
10
|
-
framework.container.
|
10
|
+
framework.container.cronTasks = new index_cjs.CronTaskHandler(options.cronTasks);
|
11
11
|
}
|
12
12
|
static [framework.postInitialization]() {
|
13
13
|
this.stores.register(new index_cjs.CronTaskStore());
|
14
14
|
}
|
15
15
|
static async [framework.preLogin]() {
|
16
|
-
if (framework.container.
|
17
|
-
framework.container.
|
16
|
+
if (framework.container.cronTasks.disableSentry) return;
|
17
|
+
framework.container.cronTasks.sentry = await import('@sentry/node').catch(() => void 0);
|
18
18
|
}
|
19
19
|
static [framework.postLogin]() {
|
20
|
-
|
20
|
+
this.stores.get("cron-tasks").resumeAll();
|
21
21
|
}
|
22
22
|
};
|
23
23
|
__name(_CronTaskPlugin, "CronTaskPlugin");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/register.ts"],"names":["Plugin","preGenericsInitialization","container","CronTaskHandler","postInitialization","CronTaskStore","preLogin","postLogin","SapphireClient"],"mappings":";;;;;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuBA,gBAAO,CAAA;AAAA,EAC1C,
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":["Plugin","preGenericsInitialization","container","CronTaskHandler","postInitialization","CronTaskStore","preLogin","postLogin","SapphireClient"],"mappings":";;;;;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuBA,gBAAO,CAAA;AAAA,EAC1C,QAAwBC,mCAAyB,CAAA,CAAwB,OAAwB,EAAA;AAChG,IAAAC,mBAAA,CAAU,SAAY,GAAA,IAAIC,yBAAgB,CAAA,OAAA,CAAQ,SAAS,CAAA;AAAA;AAC5D,EAEA,QAAwBC,4BAAkB,CAAwB,GAAA;AACjE,IAAA,IAAA,CAAK,MAAO,CAAA,QAAA,CAAS,IAAIC,uBAAA,EAAe,CAAA;AAAA;AACzC,EAEA,cAA8BC,kBAAQ,CAAwB,GAAA;AAC7D,IAAI,IAAAJ,mBAAA,CAAU,UAAU,aAAe,EAAA;AACvC,IAAUA,mBAAA,CAAA,SAAA,CAAU,SAAS,MAAM,OAAO,cAAc,CAAE,CAAA,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA;AAChF,EAEA,QAAwBK,mBAAS,CAAwB,GAAA;AACxD,IAAA,IAAA,CAAK,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAE,SAAU,EAAA;AAAA;AAE1C,CAAA;AAjB2C,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApC,IAAM,cAAN,GAAA;AAmBPC,wBAAA,CAAe,OAAQ,CAAA,qCAAA,CAAsC,cAAe,CAAAP,mCAAyB,GAAG,qCAAqC,CAAA;AAE7IO,wBAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,cAAe,CAAAJ,4BAAkB,GAAG,8BAA8B,CAAA;AAExHI,wBAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,cAAe,CAAAF,kBAAQ,GAAG,oBAAoB,CAAA;AAE1FE,wBAAA,CAAe,OAAQ,CAAA,qBAAA,CAAsB,cAAe,CAAAD,mBAAS,GAAG,qBAAqB,CAAA","file":"register.cjs","sourcesContent":["import './index';\n\nimport { container, Plugin, postInitialization, postLogin, preGenericsInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { CronTaskHandler, CronTaskStore } from './index';\n\nexport class CronTaskPlugin extends Plugin {\n\tpublic static override [preGenericsInitialization](this: SapphireClient, options: ClientOptions) {\n\t\tcontainer.cronTasks = new CronTaskHandler(options.cronTasks);\n\t}\n\n\tpublic static override [postInitialization](this: SapphireClient) {\n\t\tthis.stores.register(new CronTaskStore());\n\t}\n\n\tpublic static override async [preLogin](this: SapphireClient) {\n\t\tif (container.cronTasks.disableSentry) return;\n\t\tcontainer.cronTasks.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tthis.stores.get('cron-tasks').resumeAll();\n\t}\n}\n\nSapphireClient.plugins.registerPreGenericsInitializationHook(CronTaskPlugin[preGenericsInitialization], 'Cron-Task-PreGenericsInitialization');\n\nSapphireClient.plugins.registerPostInitializationHook(CronTaskPlugin[postInitialization], 'Cron-Task-PostInitialization');\n\nSapphireClient.plugins.registerPreLoginHook(CronTaskPlugin[preLogin], 'Cron-Task-PreLogin');\n\nSapphireClient.plugins.registerPostLoginHook(CronTaskPlugin[postLogin], 'Cron-Task-PostLogin');\n"]}
|
package/dist/esm/index.d.mts
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
import { Piece, Store } from '@sapphire/pieces';
|
2
2
|
import { Awaitable } from '@sapphire/framework';
|
3
|
-
import {
|
3
|
+
import { CronOptions, Cron } from 'croner';
|
4
4
|
import Sentry from '@sentry/node';
|
5
5
|
|
6
6
|
interface CronTaskHandlerOptions {
|
7
7
|
/**
|
8
|
-
* The default timezone to use for all cron
|
9
|
-
* You can override this per task, using the
|
10
|
-
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
11
|
-
* @default 'system'
|
8
|
+
* The default IANA timezone to use for all cron jobs.
|
9
|
+
* You can override this per task, using the timezone option.
|
12
10
|
*/
|
13
|
-
defaultTimezone
|
11
|
+
defaultTimezone?: string;
|
14
12
|
/**
|
15
13
|
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
16
14
|
* If you don't use Sentry, you can ignore this option.
|
@@ -19,7 +17,15 @@ interface CronTaskHandlerOptions {
|
|
19
17
|
*/
|
20
18
|
disableSentry: boolean;
|
21
19
|
}
|
22
|
-
|
20
|
+
interface CronJobOptions extends Pick<CronOptions, 'maxRuns' | 'unref' | 'timezone'> {
|
21
|
+
pattern: string | Date;
|
22
|
+
/**
|
23
|
+
* If true, prevents the job from running if the previous execution is still in progress.
|
24
|
+
* If the task has a protect method, it will be called if the job is blocked.
|
25
|
+
* @default false
|
26
|
+
*/
|
27
|
+
protect?: boolean;
|
28
|
+
}
|
23
29
|
|
24
30
|
/**
|
25
31
|
* @example
|
@@ -32,7 +38,7 @@ type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete
|
|
32
38
|
* public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
|
33
39
|
* super(context, {
|
34
40
|
* ...options,
|
35
|
-
*
|
41
|
+
* pattern: '* * * * *'
|
36
42
|
* });
|
37
43
|
* }
|
38
44
|
*
|
@@ -43,9 +49,11 @@ type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete
|
|
43
49
|
* ```
|
44
50
|
*/
|
45
51
|
declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
|
46
|
-
job:
|
52
|
+
job: Cron;
|
47
53
|
constructor(context: CronTask.LoaderContext, options: Options);
|
48
54
|
abstract run(): Awaitable<unknown>;
|
55
|
+
abstract protect?(job: Cron): Awaitable<unknown>;
|
56
|
+
abstract catch?(error: unknown, job: Cron): Awaitable<unknown>;
|
49
57
|
/**
|
50
58
|
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
51
59
|
* @param message The message to include after the prefix
|
@@ -97,33 +105,60 @@ declare namespace CronTask {
|
|
97
105
|
declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
|
98
106
|
constructor();
|
99
107
|
/**
|
100
|
-
* Loops over all tasks and
|
101
|
-
*
|
108
|
+
* Loops over all tasks and pauses those that are running.
|
109
|
+
*
|
110
|
+
* @remarks
|
111
|
+
* This method will only pause tasks that:
|
112
|
+
* - Are enabled
|
113
|
+
* - Are currently running
|
114
|
+
* - Have not been permanently stopped
|
115
|
+
*
|
102
116
|
* @returns CronTaskStore
|
103
117
|
*/
|
104
|
-
|
118
|
+
pauseAll(): this;
|
119
|
+
/**
|
120
|
+
* Loops over all tasks and resumes those that are paused.
|
121
|
+
*
|
122
|
+
* @remarks
|
123
|
+
* This method will only resume tasks that:
|
124
|
+
* - Are enabled
|
125
|
+
* - Are not currently running
|
126
|
+
* - Have not been permanently stopped
|
127
|
+
*
|
128
|
+
* @returns CronTaskStore
|
129
|
+
*/
|
130
|
+
resumeAll(): this;
|
105
131
|
/**
|
106
132
|
* Loops over all tasks and stops those that are running.
|
133
|
+
*
|
134
|
+
* @remarks
|
135
|
+
* This method will only stop tasks that:
|
136
|
+
* - Are enabled
|
137
|
+
* - Have not been permanently stopped
|
138
|
+
*
|
139
|
+
* ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!
|
140
|
+
*
|
107
141
|
* @returns CronTaskStore
|
108
142
|
*/
|
109
143
|
stopAll(): this;
|
110
144
|
set(key: string, value: CronTask): this;
|
145
|
+
/**
|
146
|
+
* Deletes a task from the store and stops it if it's running.
|
147
|
+
*/
|
111
148
|
delete(key: string): boolean;
|
112
149
|
/**
|
113
150
|
* Stops all running cron jobs and clears the store.
|
114
|
-
* @returns void
|
115
151
|
*/
|
116
152
|
clear(): void;
|
117
153
|
}
|
118
154
|
|
119
155
|
declare class CronTaskHandler {
|
120
156
|
/**
|
121
|
-
* The default timezone to use for all cron
|
122
|
-
* You can override this per task, using the
|
123
|
-
* @see https://
|
124
|
-
* @default 'system'
|
157
|
+
* The default IANA/TZ timezone to use for all cron jobs.
|
158
|
+
* You can override this per task, using the timezone option.
|
159
|
+
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
125
160
|
*/
|
126
|
-
defaultTimezone
|
161
|
+
defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];
|
127
162
|
/**
|
128
163
|
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
129
164
|
* If you don't use Sentry, you can ignore this option.
|
@@ -137,25 +172,12 @@ declare class CronTaskHandler {
|
|
137
172
|
* is installed and the {@linkcode disableSentry} option is set to false.
|
138
173
|
*/
|
139
174
|
sentry?: typeof Sentry;
|
140
|
-
constructor(options?: CronTaskHandlerOptions);
|
141
|
-
/**
|
142
|
-
* Start all enabled cron jobs.
|
143
|
-
* This gets called automatically when the Client is ready.
|
144
|
-
*/
|
145
|
-
startAll(): void;
|
146
|
-
/**
|
147
|
-
* Stop all running cron jobs.
|
148
|
-
*/
|
149
|
-
stopAll(): void;
|
150
|
-
/**
|
151
|
-
* Get the cron task store.
|
152
|
-
*/
|
153
|
-
private get store();
|
175
|
+
constructor(options?: Partial<CronTaskHandlerOptions>);
|
154
176
|
}
|
155
177
|
|
156
178
|
declare module '@sapphire/pieces' {
|
157
179
|
interface Container {
|
158
|
-
|
180
|
+
cronTasks: CronTaskHandler;
|
159
181
|
}
|
160
182
|
interface StoreRegistryEntries {
|
161
183
|
'cron-tasks': CronTaskStore;
|
@@ -163,7 +185,7 @@ declare module '@sapphire/pieces' {
|
|
163
185
|
}
|
164
186
|
declare module 'discord.js' {
|
165
187
|
interface ClientOptions {
|
166
|
-
|
188
|
+
cronTasks?: Partial<CronTaskHandlerOptions>;
|
167
189
|
}
|
168
190
|
}
|
169
191
|
/**
|
@@ -174,4 +196,5 @@ declare module 'discord.js' {
|
|
174
196
|
*/
|
175
197
|
declare const version: string;
|
176
198
|
|
177
|
-
export {
|
199
|
+
export { CronTask, CronTaskHandler, CronTaskStore, version };
|
200
|
+
export type { CronJobOptions, CronTaskHandlerOptions };
|
package/dist/esm/index.mjs
CHANGED
@@ -4,7 +4,7 @@ export * from './lib/structures/CronTask.mjs';
|
|
4
4
|
export * from './lib/structures/CronTaskStore.mjs';
|
5
5
|
export * from './lib/types/CronTaskTypes.mjs';
|
6
6
|
|
7
|
-
var version = "3.0.
|
7
|
+
var version = "3.0.2-next.69cca0b";
|
8
8
|
|
9
9
|
export { version };
|
10
10
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcronTasks: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcronTasks?: Partial<CronTaskHandlerOptions>;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '3.0.2-next.69cca0b';\n"]}
|
@@ -1,13 +1,12 @@
|
|
1
1
|
import { __name, __publicField } from '../chunk-2JTKI4GS.mjs';
|
2
|
-
import { container } from '@sapphire/framework';
|
3
2
|
|
3
|
+
// src/lib/CronTaskHandler.ts
|
4
4
|
var _CronTaskHandler = class _CronTaskHandler {
|
5
5
|
constructor(options) {
|
6
6
|
/**
|
7
|
-
* The default timezone to use for all cron
|
8
|
-
* You can override this per task, using the
|
9
|
-
* @see https://
|
10
|
-
* @default 'system'
|
7
|
+
* The default IANA/TZ timezone to use for all cron jobs.
|
8
|
+
* You can override this per task, using the timezone option.
|
9
|
+
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
11
10
|
*/
|
12
11
|
__publicField(this, "defaultTimezone");
|
13
12
|
/**
|
@@ -23,28 +22,9 @@ var _CronTaskHandler = class _CronTaskHandler {
|
|
23
22
|
* is installed and the {@linkcode disableSentry} option is set to false.
|
24
23
|
*/
|
25
24
|
__publicField(this, "sentry");
|
26
|
-
this.defaultTimezone = options?.defaultTimezone
|
25
|
+
this.defaultTimezone = options?.defaultTimezone;
|
27
26
|
this.disableSentry = options?.disableSentry ?? false;
|
28
27
|
}
|
29
|
-
/**
|
30
|
-
* Start all enabled cron jobs.
|
31
|
-
* This gets called automatically when the Client is ready.
|
32
|
-
*/
|
33
|
-
startAll() {
|
34
|
-
this.store.startAll();
|
35
|
-
}
|
36
|
-
/**
|
37
|
-
* Stop all running cron jobs.
|
38
|
-
*/
|
39
|
-
stopAll() {
|
40
|
-
this.store.stopAll();
|
41
|
-
}
|
42
|
-
/**
|
43
|
-
* Get the cron task store.
|
44
|
-
*/
|
45
|
-
get store() {
|
46
|
-
return container.stores.get("cron-tasks");
|
47
|
-
}
|
48
28
|
};
|
49
29
|
__name(_CronTaskHandler, "CronTaskHandler");
|
50
30
|
var CronTaskHandler = _CronTaskHandler;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;AAGO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAuBrB,YAAY,OAA2C,EAAA;AAjB9D;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAS,EAAA,eAAA;AAChC,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,KAAA;AAAA;AAEjD,CAAA;AA3B6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.mjs","sourcesContent":["import type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default IANA/TZ timezone to use for all cron jobs.\n\t * You can override this per task, using the timezone option.\n\t * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n\t */\n\tpublic defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];\n\n\t/**\n\t * The ability to opt-out of instrumenting cron jobs with Sentry.\n\t * If you don't use Sentry, you can ignore this option.\n\t * @see https://docs.sentry.io/product/crons/\n\t * @default false\n\t */\n\tpublic disableSentry: boolean;\n\n\t/**\n\t * The Sentry instance to use for instrumenting cron jobs.\n\t * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)\n\t * is installed and the {@linkcode disableSentry} option is set to false.\n\t */\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: Partial<CronTaskHandlerOptions>) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsE,KAA6B,CAAA;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAkB,EAAA;AACrE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsE,KAA6B,CAAA;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAkB,EAAA;AACrE,IAAA,KAAA,CAAM,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AAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAE3E,CAAA;AAnEyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.mjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { Cron } from 'croner';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\n\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tpattern: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\tdeclare public job: Cron;\n\n\tpublic constructor(context: CronTask.LoaderContext, options: Options) {\n\t\tsuper(context, options);\n\t}\n\n\tpublic abstract run(): Awaitable<unknown>;\n\n\tpublic abstract protect?(job: Cron): Awaitable<unknown>;\n\n\tpublic abstract catch?(error: unknown, job: Cron): Awaitable<unknown>;\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.info('Hello world!'); // CronTask[my-task] Hello world!\n\t */\n\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!\n\t */\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!\n\t */\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!\n\t */\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.\n\t */\n\tpublic trace(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n}\n\nexport namespace CronTask {\n\texport type Options = Piece.Options & CronJobOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'cron-tasks'>;\n}\n"]}
|