@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.
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var pieces = require('@sapphire/pieces');
4
- var cron = require('cron');
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 starts those that are enabled.
15
- * This gets called automatically when the Client is ready.
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
- startAll() {
25
+ pauseAll() {
19
26
  for (const task of this.values()) {
20
- if (!task.enabled) continue;
21
- task.job.start();
27
+ if (!task.enabled || !task.job.isRunning()) continue;
28
+ task.job.pause();
22
29
  }
23
- pieces.Store.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);
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.running) continue;
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.cron;
41
- const cronJob = sentry ? sentry.cron.instrumentCron(cron.CronJob, key) : cron.CronJob;
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
- value.job = cronJob.from({
44
- ...options,
45
- onTick: /* @__PURE__ */ __name(() => void value.run.bind(value)(), "onTick"),
46
- start: false,
47
- context: value,
48
- timeZone: options.timeZone ?? defaultTimezone
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?.job.running) {
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","CronJob"],"mappings":";;;;;;;;AAIO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,YAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAMC,qBAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA,CAAA;AAAA,GACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAW,GAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,KAAK,OAAS,EAAA,SAAA;AACnB,MAAA,IAAA,CAAK,IAAI,KAAM,EAAA,CAAA;AAAA,KAChB;AAEA,IAAAD,YAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CA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A,CAAM,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,GAC5B;AAAA,EAEgB,OAAO,GAAa,EAAA;AACnC,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,GAAA,CAAI,GAAG,CAAA,CAAA;AACzB,IAAI,IAAA,IAAA,EAAM,IAAI,OAAS,EAAA;AACtB,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA,CAAA;AAAA,KACf;AAEA,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA,CAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AAzEiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { CronJob } from 'cron';\nimport { CronTask } from './CronTask';\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 starts those that are enabled.\n\t * This gets called automatically when the Client is ready.\n\t * @returns CronTaskStore\n\t */\n\tpublic startAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled) continue;\n\t\t\ttask.job.start();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [START] Started 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 * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.job.running) 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 { options } = value;\n\n\t\tconst { sentry, defaultTimezone } = this.container.cron;\n\t\tconst cronJob = sentry ? sentry.cron.instrumentCron(CronJob, key) : CronJob;\n\n\t\ttry {\n\t\t\tvalue.job = cronJob.from({\n\t\t\t\t...options,\n\t\t\t\tonTick: () => void value.run.bind(value)(),\n\t\t\t\tstart: false,\n\t\t\t\tcontext: value,\n\t\t\t\ttimeZone: options.timeZone ?? defaultTimezone\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\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task?.job.running) {\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 * @returns void\n\t */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
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,IAAI,CAAC,IAAK,CAAA,OAAA,IAAW,CAAC,IAAK,CAAA,GAAA,CAAI,WAAa,EAAA;AAC5C,MAAA,IAAA,CAAK,IAAI,KAAM,EAAA;AAAA;AAGhB,IAAAD,YAAA,CAAM,MA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AAA,IAAA,CAAK,KAAK,CAAA,EAAK,EAAA;AAAA,cAClE,QAAU,EAAA,EAAE,IAAM,EAAA,SAAA,EAAW,OAAO,OAAQ,EAAA;AAAA,cAC5C,QAAU,EAAA,QAAA,GAAWC,qCAAiB,CAAA,QAAQ,CAAI,GAAA,KAAA;AAAA,aAClD,CAAA;AAAA;AAGF,UAAA,OAAO,KAAM,CAAA,GAAA,CAAI,IAAK,CAAA,KAAK,CAAE,EAAA;AAAA;AAC9B,OACD;AAAA,aACQ,KAAO,EAAA;AACf,MAAM,KAAA,CAAA,KAAA,CAAM,oDAAoD,KAAK,CAAA;AACrE,MAAA,KAAK,MAAM,MAAO,EAAA;AAAA;AAGnB,IAAO,OAAA,KAAA,CAAM,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA;AAAA;AAC5B;AAAA;AAAA;AAAA,EAKgB,OAAO,GAAa,EAAA;AACnC,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,GAAA,CAAI,GAAG,CAAA;AACzB,IAAA,IAAI,IAAQ,IAAA,CAAC,IAAK,CAAA,GAAA,CAAI,WAAa,EAAA;AAClC,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA;AAAA;AAGf,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA;AACxB;AAAA;AAAA;AAAA,EAKgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA;AAAA;AAErB,CAAA;AA3IiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Cron } from 'croner';\nimport { CronTask } 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"]}
@@ -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.cron = new index_cjs.CronTaskHandler(options.cron);
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.cron.disableSentry) return;
17
- framework.container.cron.sentry = await import('@sentry/node').then((mod) => mod.default).catch(() => void 0);
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
- framework.container.cron.startAll();
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,QAAeC,mCAAyB,CAAA,CAAwB,OAAwB,EAAA;AACvF,IAAAC,mBAAA,CAAU,IAAO,GAAA,IAAIC,yBAAgB,CAAA,OAAA,CAAQ,IAAI,CAAA,CAAA;AAAA,GAClD;AAAA,EAEA,QAAeC,4BAAkB,CAAwB,GAAA;AACxD,IAAA,IAAA,CAAK,MAAO,CAAA,QAAA,CAAS,IAAIC,uBAAA,EAAe,CAAA,CAAA;AAAA,GACzC;AAAA,EAEA,cAAqBC,kBAAQ,CAAwB,GAAA;AACpD,IAAI,IAAAJ,mBAAA,CAAU,KAAK,aAAe,EAAA,OAAA;AAClC,IAAAA,mBAAA,CAAU,IAAK,CAAA,MAAA,GAAS,MAAM,OAAO,cAAc,CAAE,CAAA,IAAA,CAAK,CAAC,GAAA,KAAQ,GAAI,CAAA,OAAO,CAAE,CAAA,KAAA,CAAM,MAAM,KAAS,CAAA,CAAA,CAAA;AAAA,GACtG;AAAA,EAEA,QAAeK,mBAAS,CAAwB,GAAA;AAC/C,IAAAL,mBAAA,CAAU,KAAK,QAAS,EAAA,CAAA;AAAA,GACzB;AACD,CAAA,CAAA;AAjB2C,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA,CAAA;AAApC,IAAM,cAAN,GAAA,gBAAA;AAmBPM,wBAAA,CAAe,OAAQ,CAAA,qCAAA,CAAsC,cAAe,CAAAP,mCAAyB,GAAG,qCAAqC,CAAA,CAAA;AAE7IO,wBAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,cAAe,CAAAJ,4BAAkB,GAAG,8BAA8B,CAAA,CAAA;AAExHI,wBAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,cAAe,CAAAF,kBAAQ,GAAG,oBAAoB,CAAA,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 [preGenericsInitialization](this: SapphireClient, options: ClientOptions) {\n\t\tcontainer.cron = new CronTaskHandler(options.cron);\n\t}\n\n\tpublic static [postInitialization](this: SapphireClient) {\n\t\tthis.stores.register(new CronTaskStore());\n\t}\n\n\tpublic static async [preLogin](this: SapphireClient) {\n\t\tif (container.cron.disableSentry) return;\n\t\tcontainer.cron.sentry = await import('@sentry/node').then((mod) => mod.default).catch(() => undefined);\n\t}\n\n\tpublic static [postLogin](this: SapphireClient) {\n\t\tcontainer.cron.startAll();\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"]}
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"]}
@@ -1,16 +1,14 @@
1
1
  import { Piece, Store } from '@sapphire/pieces';
2
2
  import { Awaitable } from '@sapphire/framework';
3
- import { CronJobParams, CronJob } from 'cron';
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 tasks.
9
- * You can override this per task, using the timeZone option.
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: string;
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
- type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
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
- * cronTime: '* * * * *'
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: CronJob<null, CronTask>;
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 starts those that are enabled.
101
- * This gets called automatically when the Client is ready.
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
- startAll(): this;
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 tasks.
122
- * You can override this per task, using the timeZone option.
123
- * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
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: CronTaskHandlerOptions['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
- cron: CronTaskHandler;
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
- cron?: CronTaskHandlerOptions;
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 { type CronJobOptions, CronTask, CronTaskHandler, type CronTaskHandlerOptions, CronTaskStore, version };
199
+ export { CronTask, CronTaskHandler, CronTaskStore, version };
200
+ export type { CronJobOptions, CronTaskHandlerOptions };
@@ -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.1-next.e1b3c15";
7
+ var version = "3.0.2-next.69cca0b";
8
8
 
9
9
  export { version };
10
10
  //# sourceMappingURL=index.mjs.map
@@ -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\tcron: 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\tcron?: 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.1-next.e1b3c15';\n"]}
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 tasks.
8
- * You can override this per task, using the timeZone option.
9
- * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
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 ?? "system";
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":";;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAwBrB,YAAY,OAAkC,EAAA;AAjBrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGN,IAAK,IAAA,CAAA,eAAA,GAAkB,SAAS,eAAmB,IAAA,QAAA,CAAA;AACnD,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,KAAA,CAAA;AAAA,GAChD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAW,GAAA;AACjB,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACrB;AAAA;AAAA;AAAA;AAAA,EAKO,OAAU,GAAA;AAChB,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACpB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAY,KAAQ,GAAA;AACnB,IAAO,OAAA,SAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GACzC;AACD,CAAA,CAAA;AAlD6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.mjs","sourcesContent":["import { container } from '@sapphire/framework';\nimport type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default timezone to use for all cron tasks.\n\t * You can override this per task, using the timeZone option.\n\t * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone\n\t * @default 'system'\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?: CronTaskHandlerOptions) {\n\t\tthis.defaultTimezone = options?.defaultTimezone ?? 'system';\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n\n\t/**\n\t * Start all enabled cron jobs.\n\t * This gets called automatically when the Client is ready.\n\t */\n\tpublic startAll() {\n\t\tthis.store.startAll();\n\t}\n\n\t/**\n\t * Stop all running cron jobs.\n\t */\n\tpublic stopAll() {\n\t\tthis.store.stopAll();\n\t}\n\n\t/**\n\t * Get the cron task store.\n\t */\n\tprivate get store() {\n\t\treturn container.stores.get('cron-tasks');\n\t}\n}\n"]}
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,CAAA;AAAA,GACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AACD,CAAA,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.mjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { CronJob } from 'cron';\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\tcronTime: '* * * * *'\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\tpublic declare job: CronJob<null, CronTask>;\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\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'>;\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;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,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"]}