@kingsworld/plugin-cron 2.1.2-next.a581de3 → 2.1.2-pr-102.f10de0b
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/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +43 -50
- 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 +77 -33
- package/dist/cjs/lib/structures/CronTaskStore.cjs.map +1 -1
- package/dist/cjs/register.cjs +1 -1
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/esm/index.d.mts +43 -50
- 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 +77 -33
- package/dist/esm/lib/structures/CronTaskStore.mjs.map +1 -1
- package/dist/esm/register.mjs +1 -1
- package/dist/esm/register.mjs.map +1 -1
- package/package.json +4 -5
package/dist/cjs/index.cjs
CHANGED
@@ -6,7 +6,7 @@ var CronTaskStore_cjs = require('./lib/structures/CronTaskStore.cjs');
|
|
6
6
|
var CronTaskTypes_cjs = require('./lib/types/CronTaskTypes.cjs');
|
7
7
|
|
8
8
|
// src/index.ts
|
9
|
-
var version = "2.1.2-
|
9
|
+
var version = "2.1.2-pr-102.f10de0b";
|
10
10
|
|
11
11
|
exports.version = version;
|
12
12
|
Object.keys(CronTaskHandler_cjs).forEach(function (k) {
|
package/dist/cjs/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.cjs","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?: 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 = '2.1.2-
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.cjs","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?: 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 = '2.1.2-pr-102.f10de0b';\n"]}
|
package/dist/cjs/index.d.cts
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,19 +17,8 @@ interface CronTaskHandlerOptions {
|
|
19
17
|
*/
|
20
18
|
disableSentry: boolean;
|
21
19
|
}
|
22
|
-
|
23
|
-
|
24
|
-
* The @types/luxon package doesn't seem to be up-to-date with luxon.
|
25
|
-
* Therefore, I have to manually add the ianaName getter to the FixedOffsetZone class.
|
26
|
-
* The code can be found here: https://github.com/moment/luxon/blob/3e9983cd0680fdf7836fcee638d34e3edc682380/src/zones/fixedOffsetZone.js#L80C7-L80C15
|
27
|
-
*/
|
28
|
-
declare module 'luxon' {
|
29
|
-
interface FixedOffsetZone {
|
30
|
-
/**
|
31
|
-
* The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn`
|
32
|
-
*/
|
33
|
-
get ianaName(): string;
|
34
|
-
}
|
20
|
+
interface CronJobOptions extends Pick<CronOptions, 'maxRuns' | 'protect' | 'unref' | 'timezone'> {
|
21
|
+
pattern: string;
|
35
22
|
}
|
36
23
|
|
37
24
|
/**
|
@@ -56,7 +43,7 @@ declare module 'luxon' {
|
|
56
43
|
* ```
|
57
44
|
*/
|
58
45
|
declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
|
59
|
-
job:
|
46
|
+
job: Cron;
|
60
47
|
constructor(context: CronTask.LoaderContext, options: Options);
|
61
48
|
abstract run(): Awaitable<unknown>;
|
62
49
|
/**
|
@@ -110,41 +97,60 @@ declare namespace CronTask {
|
|
110
97
|
declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
|
111
98
|
constructor();
|
112
99
|
/**
|
113
|
-
* Loops over all tasks and
|
114
|
-
*
|
100
|
+
* Loops over all tasks and pauses those that are running.
|
101
|
+
*
|
102
|
+
* @remarks
|
103
|
+
* This method will only pause tasks that:
|
104
|
+
* - Are enabled
|
105
|
+
* - Are currently running
|
106
|
+
* - Have not been permanently stopped
|
107
|
+
*
|
108
|
+
* @returns CronTaskStore
|
109
|
+
*/
|
110
|
+
pauseAll(): this;
|
111
|
+
/**
|
112
|
+
* Loops over all tasks and resumes those that are paused.
|
113
|
+
*
|
114
|
+
* @remarks
|
115
|
+
* This method will only resume tasks that:
|
116
|
+
* - Are enabled
|
117
|
+
* - Are not currently running
|
118
|
+
* - Have not been permanently stopped
|
119
|
+
*
|
115
120
|
* @returns CronTaskStore
|
116
121
|
*/
|
117
|
-
|
122
|
+
resumeAll(): this;
|
118
123
|
/**
|
119
124
|
* Loops over all tasks and stops those that are running.
|
125
|
+
*
|
126
|
+
* @remarks
|
127
|
+
* This method will only stop tasks that:
|
128
|
+
* - Are enabled
|
129
|
+
* - Have not been permanently stopped
|
130
|
+
*
|
131
|
+
* ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!
|
132
|
+
*
|
120
133
|
* @returns CronTaskStore
|
121
134
|
*/
|
122
135
|
stopAll(): this;
|
123
136
|
set(key: string, value: CronTask): this;
|
137
|
+
/**
|
138
|
+
* Deletes a task from the store and stops it if it's running.
|
139
|
+
*/
|
124
140
|
delete(key: string): boolean;
|
125
141
|
/**
|
126
142
|
* Stops all running cron jobs and clears the store.
|
127
|
-
* @returns void
|
128
143
|
*/
|
129
144
|
clear(): void;
|
130
|
-
/**
|
131
|
-
* Formats a Luxon-compatible timezone string into a TZ timezone string.
|
132
|
-
* This is required because Sentry requires time zones to be in TZ format.
|
133
|
-
* @param timezone The Luxon-compatible timezone to format.
|
134
|
-
* @returns The formatted TZ timezone.
|
135
|
-
* @private
|
136
|
-
*/
|
137
|
-
private formatLuxonZone;
|
138
145
|
}
|
139
146
|
|
140
147
|
declare class CronTaskHandler {
|
141
148
|
/**
|
142
|
-
* The default timezone to use for all cron
|
143
|
-
* You can override this per task, using the
|
144
|
-
* @see https://
|
145
|
-
* @default 'system'
|
149
|
+
* The default IANA/TZ timezone to use for all cron jobs.
|
150
|
+
* You can override this per task, using the timezone option.
|
151
|
+
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
146
152
|
*/
|
147
|
-
defaultTimezone
|
153
|
+
defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];
|
148
154
|
/**
|
149
155
|
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
150
156
|
* If you don't use Sentry, you can ignore this option.
|
@@ -159,19 +165,6 @@ declare class CronTaskHandler {
|
|
159
165
|
*/
|
160
166
|
sentry?: typeof Sentry;
|
161
167
|
constructor(options?: Partial<CronTaskHandlerOptions>);
|
162
|
-
/**
|
163
|
-
* Start all enabled cron jobs.
|
164
|
-
* This gets called automatically when the Client is ready.
|
165
|
-
*/
|
166
|
-
startAll(): void;
|
167
|
-
/**
|
168
|
-
* Stop all running cron jobs.
|
169
|
-
*/
|
170
|
-
stopAll(): void;
|
171
|
-
/**
|
172
|
-
* Get the cron task store.
|
173
|
-
*/
|
174
|
-
private get store();
|
175
168
|
}
|
176
169
|
|
177
170
|
declare module '@sapphire/pieces' {
|
@@ -1,18 +1,17 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var framework = require('@sapphire/framework');
|
4
|
-
|
5
3
|
var __defProp = Object.defineProperty;
|
6
4
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
7
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
8
6
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
7
|
+
|
8
|
+
// src/lib/CronTaskHandler.ts
|
9
9
|
var _CronTaskHandler = class _CronTaskHandler {
|
10
10
|
constructor(options) {
|
11
11
|
/**
|
12
|
-
* The default timezone to use for all cron
|
13
|
-
* You can override this per task, using the
|
14
|
-
* @see https://
|
15
|
-
* @default 'system'
|
12
|
+
* The default IANA/TZ timezone to use for all cron jobs.
|
13
|
+
* You can override this per task, using the timezone option.
|
14
|
+
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
16
15
|
*/
|
17
16
|
__publicField(this, "defaultTimezone");
|
18
17
|
/**
|
@@ -28,28 +27,9 @@ var _CronTaskHandler = class _CronTaskHandler {
|
|
28
27
|
* is installed and the {@linkcode disableSentry} option is set to false.
|
29
28
|
*/
|
30
29
|
__publicField(this, "sentry");
|
31
|
-
this.defaultTimezone = options?.defaultTimezone
|
30
|
+
this.defaultTimezone = options?.defaultTimezone;
|
32
31
|
this.disableSentry = options?.disableSentry ?? false;
|
33
32
|
}
|
34
|
-
/**
|
35
|
-
* Start all enabled cron jobs.
|
36
|
-
* This gets called automatically when the Client is ready.
|
37
|
-
*/
|
38
|
-
startAll() {
|
39
|
-
this.store.startAll();
|
40
|
-
}
|
41
|
-
/**
|
42
|
-
* Stop all running cron jobs.
|
43
|
-
*/
|
44
|
-
stopAll() {
|
45
|
-
this.store.stopAll();
|
46
|
-
}
|
47
|
-
/**
|
48
|
-
* Get the cron task store.
|
49
|
-
*/
|
50
|
-
get store() {
|
51
|
-
return framework.container.stores.get("cron-tasks");
|
52
|
-
}
|
53
33
|
};
|
54
34
|
__name(_CronTaskHandler, "CronTaskHandler");
|
55
35
|
var CronTaskHandler = _CronTaskHandler;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[
|
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.cjs","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":["Piece"],"mappings":";;;;;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsEA,YAA6B,CAAA;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAkB,EAAA;AACrE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAAA;AACvB;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;AAAA;AACzE;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;AAAA;AAC1E;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;AAAA;AACzE;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;AAAA;AAC1E;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;AAAA;AAE3E,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.cjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type {
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":["Piece"],"mappings":";;;;;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsEA,YAA6B,CAAA;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAkB,EAAA;AACrE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAAA;AACvB;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;AAAA;AACzE;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;AAAA;AAC1E;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;AAAA;AACzE;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;AAAA;AAC1E;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;AAAA;AAE3E,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.cjs","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\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\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\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"]}
|
@@ -1,9 +1,8 @@
|
|
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 luxon = require('luxon');
|
7
6
|
|
8
7
|
var __defProp = Object.defineProperty;
|
9
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
@@ -12,76 +11,121 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
12
11
|
super(CronTask_cjs.CronTask, { name: "cron-tasks" });
|
13
12
|
}
|
14
13
|
/**
|
15
|
-
* Loops over all tasks and
|
16
|
-
*
|
14
|
+
* Loops over all tasks and pauses those that are running.
|
15
|
+
*
|
16
|
+
* @remarks
|
17
|
+
* This method will only pause tasks that:
|
18
|
+
* - Are enabled
|
19
|
+
* - Are currently running
|
20
|
+
* - Have not been permanently stopped
|
21
|
+
*
|
17
22
|
* @returns CronTaskStore
|
18
23
|
*/
|
19
|
-
|
24
|
+
pauseAll() {
|
20
25
|
for (const task of this.values()) {
|
21
|
-
if (!task.enabled) continue;
|
22
|
-
task.job.
|
26
|
+
if (!task.enabled || !task.job.isRunning()) continue;
|
27
|
+
task.job.pause();
|
23
28
|
}
|
24
|
-
pieces.Store.logger?.(`[STORE => ${this.name}] [
|
29
|
+
pieces.Store.logger?.(`[STORE => ${this.name}] [PAUSE] Paused all cronjob tasks.`);
|
30
|
+
return this;
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Loops over all tasks and resumes those that are paused.
|
34
|
+
*
|
35
|
+
* @remarks
|
36
|
+
* This method will only resume tasks that:
|
37
|
+
* - Are enabled
|
38
|
+
* - Are not currently running
|
39
|
+
* - Have not been permanently stopped
|
40
|
+
*
|
41
|
+
* @returns CronTaskStore
|
42
|
+
*/
|
43
|
+
resumeAll() {
|
44
|
+
for (const task of this.values()) {
|
45
|
+
if (!task.enabled || task.job.isRunning() || task.job.isStopped()) continue;
|
46
|
+
task.job.resume();
|
47
|
+
}
|
48
|
+
pieces.Store.logger?.(`[STORE => ${this.name}] [RESUME] Resumed all cronjob tasks.`);
|
25
49
|
return this;
|
26
50
|
}
|
27
51
|
/**
|
28
52
|
* Loops over all tasks and stops those that are running.
|
53
|
+
*
|
54
|
+
* @remarks
|
55
|
+
* This method will only stop tasks that:
|
56
|
+
* - Are enabled
|
57
|
+
* - Have not been permanently stopped
|
58
|
+
*
|
59
|
+
* ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!
|
60
|
+
*
|
29
61
|
* @returns CronTaskStore
|
30
62
|
*/
|
31
63
|
stopAll() {
|
32
64
|
for (const task of this.values()) {
|
33
|
-
if (!task.job.
|
65
|
+
if (!task.enabled || task.job.isStopped()) continue;
|
34
66
|
task.job.stop();
|
35
67
|
}
|
36
68
|
pieces.Store.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);
|
37
69
|
return this;
|
38
70
|
}
|
39
71
|
set(key, value) {
|
40
|
-
const { options } = value;
|
72
|
+
const { pattern, timezone, ...options } = value.options;
|
41
73
|
const { sentry, defaultTimezone } = this.container.cron;
|
42
|
-
|
74
|
+
if (this.has(key)) {
|
75
|
+
pieces.Store.logger?.(`[STORE => ${this.name}] [SET] Stopping existing cronjob task before creating a new one.`);
|
76
|
+
this.get(key)?.job.stop();
|
77
|
+
}
|
78
|
+
const timeZone = timezone ?? defaultTimezone;
|
43
79
|
try {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
80
|
+
pieces.Store.logger?.(
|
81
|
+
`[STORE => ${this.name}] [SET] Creating cronjob for ${key} with '${pattern}' as the pattern and '${timeZone}' for the timezone`
|
82
|
+
);
|
83
|
+
value.job = new croner.Cron(
|
84
|
+
pattern,
|
85
|
+
{
|
86
|
+
name: key,
|
87
|
+
timezone: timeZone,
|
88
|
+
paused: true,
|
89
|
+
// we start the job manually once the client is ready
|
90
|
+
catch: /* @__PURE__ */ __name((error) => {
|
91
|
+
value.error("Encountered an error while running the cron job", error);
|
92
|
+
if (sentry) sentry.captureException(error);
|
93
|
+
}, "catch"),
|
94
|
+
...options
|
95
|
+
},
|
96
|
+
() => {
|
97
|
+
if (sentry) {
|
98
|
+
return sentry.withMonitor(key, () => void value.run.bind(value)(), {
|
99
|
+
schedule: { type: "crontab", value: pattern },
|
100
|
+
timezone: timeZone
|
101
|
+
});
|
102
|
+
}
|
103
|
+
return value.run.bind(value)();
|
104
|
+
}
|
105
|
+
);
|
51
106
|
} catch (error) {
|
52
107
|
value.error("Encountered an error while creating the cron job", error);
|
53
108
|
void value.unload();
|
54
109
|
}
|
55
110
|
return super.set(key, value);
|
56
111
|
}
|
112
|
+
/**
|
113
|
+
* Deletes a task from the store and stops it if it's running.
|
114
|
+
*/
|
57
115
|
delete(key) {
|
58
116
|
const task = this.get(key);
|
59
|
-
if (task
|
117
|
+
if (task && !task.job.isStopped()) {
|
60
118
|
task.job.stop();
|
61
119
|
}
|
62
120
|
return super.delete(key);
|
63
121
|
}
|
64
122
|
/**
|
65
123
|
* Stops all running cron jobs and clears the store.
|
66
|
-
* @returns void
|
67
124
|
*/
|
68
125
|
clear() {
|
69
126
|
this.stopAll();
|
70
127
|
return super.clear();
|
71
128
|
}
|
72
|
-
/**
|
73
|
-
* Formats a Luxon-compatible timezone string into a TZ timezone string.
|
74
|
-
* This is required because Sentry requires time zones to be in TZ format.
|
75
|
-
* @param timezone The Luxon-compatible timezone to format.
|
76
|
-
* @returns The formatted TZ timezone.
|
77
|
-
* @private
|
78
|
-
*/
|
79
|
-
formatLuxonZone(timezone) {
|
80
|
-
const zone = luxon.Info.normalizeZone(timezone);
|
81
|
-
if (!zone.isValid) return luxon.DateTime.local().zoneName;
|
82
|
-
if (zone instanceof luxon.FixedOffsetZone) return zone.ianaName;
|
83
|
-
return zone.name;
|
84
|
-
}
|
85
129
|
};
|
86
130
|
__name(_CronTaskStore, "CronTaskStore");
|
87
131
|
var CronTaskStore = _CronTaskStore;
|
@@ -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"],"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;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,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAqC,mCAAA,CAAA,CAAA;AAC1E,IAAO,OAAA,IAAA;AAAA;AACR;AAAA;AAAA;A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,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;AAxIiE,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';\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, ...options } = value.options;\n\t\tconst { sentry, defaultTimezone } = this.container.cron;\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\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},\n\t\t\t\t\t...options\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tif (sentry) {\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\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"]}
|
package/dist/cjs/register.cjs
CHANGED
@@ -17,7 +17,7 @@ var _CronTaskPlugin = class _CronTaskPlugin extends framework.Plugin {
|
|
17
17
|
framework.container.cron.sentry = await import('@sentry/node').catch(() => void 0);
|
18
18
|
}
|
19
19
|
static [framework.postLogin]() {
|
20
|
-
framework.container.cron.
|
20
|
+
framework.container.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,QAAwBC,mCAAyB,CAAA,CAAwB,OAAwB,EAAA;AAChG,IAAAC,mBAAA,CAAU,IAAO,GAAA,IAAIC,yBAAgB,CAAA,OAAA,CAAQ,IAAI,CAAA;AAAA;AAClD,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,KAAK,aAAe,EAAA;AAClC,IAAUA,mBAAA,CAAA,IAAA,CAAK,SAAS,MAAM,OAAO,cAAc,CAAE,CAAA,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA;AAC3E,EAEA,QAAwBK,mBAAS,CAAwB,GAAA;AACxD,IAAAL,mBAAA,CAAU,
|
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,IAAO,GAAA,IAAIC,yBAAgB,CAAA,OAAA,CAAQ,IAAI,CAAA;AAAA;AAClD,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,KAAK,aAAe,EAAA;AAClC,IAAUA,mBAAA,CAAA,IAAA,CAAK,SAAS,MAAM,OAAO,cAAc,CAAE,CAAA,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA;AAC3E,EAEA,QAAwBK,mBAAS,CAAwB,GAAA;AACxD,IAAAL,mBAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAE,SAAU,EAAA;AAAA;AAE/C,CAAA;AAjB2C,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApC,IAAM,cAAN,GAAA;AAmBPM,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.cron = new CronTaskHandler(options.cron);\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.cron.disableSentry) return;\n\t\tcontainer.cron.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tcontainer.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,19 +17,8 @@ interface CronTaskHandlerOptions {
|
|
19
17
|
*/
|
20
18
|
disableSentry: boolean;
|
21
19
|
}
|
22
|
-
|
23
|
-
|
24
|
-
* The @types/luxon package doesn't seem to be up-to-date with luxon.
|
25
|
-
* Therefore, I have to manually add the ianaName getter to the FixedOffsetZone class.
|
26
|
-
* The code can be found here: https://github.com/moment/luxon/blob/3e9983cd0680fdf7836fcee638d34e3edc682380/src/zones/fixedOffsetZone.js#L80C7-L80C15
|
27
|
-
*/
|
28
|
-
declare module 'luxon' {
|
29
|
-
interface FixedOffsetZone {
|
30
|
-
/**
|
31
|
-
* The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn`
|
32
|
-
*/
|
33
|
-
get ianaName(): string;
|
34
|
-
}
|
20
|
+
interface CronJobOptions extends Pick<CronOptions, 'maxRuns' | 'protect' | 'unref' | 'timezone'> {
|
21
|
+
pattern: string;
|
35
22
|
}
|
36
23
|
|
37
24
|
/**
|
@@ -56,7 +43,7 @@ declare module 'luxon' {
|
|
56
43
|
* ```
|
57
44
|
*/
|
58
45
|
declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
|
59
|
-
job:
|
46
|
+
job: Cron;
|
60
47
|
constructor(context: CronTask.LoaderContext, options: Options);
|
61
48
|
abstract run(): Awaitable<unknown>;
|
62
49
|
/**
|
@@ -110,41 +97,60 @@ declare namespace CronTask {
|
|
110
97
|
declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
|
111
98
|
constructor();
|
112
99
|
/**
|
113
|
-
* Loops over all tasks and
|
114
|
-
*
|
100
|
+
* Loops over all tasks and pauses those that are running.
|
101
|
+
*
|
102
|
+
* @remarks
|
103
|
+
* This method will only pause tasks that:
|
104
|
+
* - Are enabled
|
105
|
+
* - Are currently running
|
106
|
+
* - Have not been permanently stopped
|
107
|
+
*
|
108
|
+
* @returns CronTaskStore
|
109
|
+
*/
|
110
|
+
pauseAll(): this;
|
111
|
+
/**
|
112
|
+
* Loops over all tasks and resumes those that are paused.
|
113
|
+
*
|
114
|
+
* @remarks
|
115
|
+
* This method will only resume tasks that:
|
116
|
+
* - Are enabled
|
117
|
+
* - Are not currently running
|
118
|
+
* - Have not been permanently stopped
|
119
|
+
*
|
115
120
|
* @returns CronTaskStore
|
116
121
|
*/
|
117
|
-
|
122
|
+
resumeAll(): this;
|
118
123
|
/**
|
119
124
|
* Loops over all tasks and stops those that are running.
|
125
|
+
*
|
126
|
+
* @remarks
|
127
|
+
* This method will only stop tasks that:
|
128
|
+
* - Are enabled
|
129
|
+
* - Have not been permanently stopped
|
130
|
+
*
|
131
|
+
* ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!
|
132
|
+
*
|
120
133
|
* @returns CronTaskStore
|
121
134
|
*/
|
122
135
|
stopAll(): this;
|
123
136
|
set(key: string, value: CronTask): this;
|
137
|
+
/**
|
138
|
+
* Deletes a task from the store and stops it if it's running.
|
139
|
+
*/
|
124
140
|
delete(key: string): boolean;
|
125
141
|
/**
|
126
142
|
* Stops all running cron jobs and clears the store.
|
127
|
-
* @returns void
|
128
143
|
*/
|
129
144
|
clear(): void;
|
130
|
-
/**
|
131
|
-
* Formats a Luxon-compatible timezone string into a TZ timezone string.
|
132
|
-
* This is required because Sentry requires time zones to be in TZ format.
|
133
|
-
* @param timezone The Luxon-compatible timezone to format.
|
134
|
-
* @returns The formatted TZ timezone.
|
135
|
-
* @private
|
136
|
-
*/
|
137
|
-
private formatLuxonZone;
|
138
145
|
}
|
139
146
|
|
140
147
|
declare class CronTaskHandler {
|
141
148
|
/**
|
142
|
-
* The default timezone to use for all cron
|
143
|
-
* You can override this per task, using the
|
144
|
-
* @see https://
|
145
|
-
* @default 'system'
|
149
|
+
* The default IANA/TZ timezone to use for all cron jobs.
|
150
|
+
* You can override this per task, using the timezone option.
|
151
|
+
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
146
152
|
*/
|
147
|
-
defaultTimezone
|
153
|
+
defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];
|
148
154
|
/**
|
149
155
|
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
150
156
|
* If you don't use Sentry, you can ignore this option.
|
@@ -159,19 +165,6 @@ declare class CronTaskHandler {
|
|
159
165
|
*/
|
160
166
|
sentry?: typeof Sentry;
|
161
167
|
constructor(options?: Partial<CronTaskHandlerOptions>);
|
162
|
-
/**
|
163
|
-
* Start all enabled cron jobs.
|
164
|
-
* This gets called automatically when the Client is ready.
|
165
|
-
*/
|
166
|
-
startAll(): void;
|
167
|
-
/**
|
168
|
-
* Stop all running cron jobs.
|
169
|
-
*/
|
170
|
-
stopAll(): void;
|
171
|
-
/**
|
172
|
-
* Get the cron task store.
|
173
|
-
*/
|
174
|
-
private get store();
|
175
168
|
}
|
176
169
|
|
177
170
|
declare module '@sapphire/pieces' {
|
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 = "2.1.2-
|
7
|
+
var version = "2.1.2-pr-102.f10de0b";
|
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\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?: 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 = '2.1.2-
|
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?: 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 = '2.1.2-pr-102.f10de0b';\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;AAAA;AACvB;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;AAAA;AACzE;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;AAAA;AAC1E;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;AAAA;AACzE;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;AAAA;AAC1E;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;AAAA;AAE3E,CAAA;AA/DyH,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 {
|
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;AAAA;AACvB;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,EA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/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\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\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\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"]}
|
@@ -1,84 +1,128 @@
|
|
1
1
|
import { __name } from '../../chunk-2JTKI4GS.mjs';
|
2
2
|
import { Store } from '@sapphire/pieces';
|
3
|
-
import {
|
3
|
+
import { Cron } from 'croner';
|
4
4
|
import { CronTask } from './CronTask.mjs';
|
5
|
-
import { Info, DateTime, FixedOffsetZone } from 'luxon';
|
6
5
|
|
7
6
|
var _CronTaskStore = class _CronTaskStore extends Store {
|
8
7
|
constructor() {
|
9
8
|
super(CronTask, { name: "cron-tasks" });
|
10
9
|
}
|
11
10
|
/**
|
12
|
-
* Loops over all tasks and
|
13
|
-
*
|
11
|
+
* Loops over all tasks and pauses those that are running.
|
12
|
+
*
|
13
|
+
* @remarks
|
14
|
+
* This method will only pause tasks that:
|
15
|
+
* - Are enabled
|
16
|
+
* - Are currently running
|
17
|
+
* - Have not been permanently stopped
|
18
|
+
*
|
14
19
|
* @returns CronTaskStore
|
15
20
|
*/
|
16
|
-
|
21
|
+
pauseAll() {
|
17
22
|
for (const task of this.values()) {
|
18
|
-
if (!task.enabled) continue;
|
19
|
-
task.job.
|
23
|
+
if (!task.enabled || !task.job.isRunning()) continue;
|
24
|
+
task.job.pause();
|
20
25
|
}
|
21
|
-
Store.logger?.(`[STORE => ${this.name}] [
|
26
|
+
Store.logger?.(`[STORE => ${this.name}] [PAUSE] Paused all cronjob tasks.`);
|
27
|
+
return this;
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* Loops over all tasks and resumes those that are paused.
|
31
|
+
*
|
32
|
+
* @remarks
|
33
|
+
* This method will only resume tasks that:
|
34
|
+
* - Are enabled
|
35
|
+
* - Are not currently running
|
36
|
+
* - Have not been permanently stopped
|
37
|
+
*
|
38
|
+
* @returns CronTaskStore
|
39
|
+
*/
|
40
|
+
resumeAll() {
|
41
|
+
for (const task of this.values()) {
|
42
|
+
if (!task.enabled || task.job.isRunning() || task.job.isStopped()) continue;
|
43
|
+
task.job.resume();
|
44
|
+
}
|
45
|
+
Store.logger?.(`[STORE => ${this.name}] [RESUME] Resumed all cronjob tasks.`);
|
22
46
|
return this;
|
23
47
|
}
|
24
48
|
/**
|
25
49
|
* Loops over all tasks and stops those that are running.
|
50
|
+
*
|
51
|
+
* @remarks
|
52
|
+
* This method will only stop tasks that:
|
53
|
+
* - Are enabled
|
54
|
+
* - Have not been permanently stopped
|
55
|
+
*
|
56
|
+
* ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!
|
57
|
+
*
|
26
58
|
* @returns CronTaskStore
|
27
59
|
*/
|
28
60
|
stopAll() {
|
29
61
|
for (const task of this.values()) {
|
30
|
-
if (!task.job.
|
62
|
+
if (!task.enabled || task.job.isStopped()) continue;
|
31
63
|
task.job.stop();
|
32
64
|
}
|
33
65
|
Store.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);
|
34
66
|
return this;
|
35
67
|
}
|
36
68
|
set(key, value) {
|
37
|
-
const { options } = value;
|
69
|
+
const { pattern, timezone, ...options } = value.options;
|
38
70
|
const { sentry, defaultTimezone } = this.container.cron;
|
39
|
-
|
71
|
+
if (this.has(key)) {
|
72
|
+
Store.logger?.(`[STORE => ${this.name}] [SET] Stopping existing cronjob task before creating a new one.`);
|
73
|
+
this.get(key)?.job.stop();
|
74
|
+
}
|
75
|
+
const timeZone = timezone ?? defaultTimezone;
|
40
76
|
try {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
77
|
+
Store.logger?.(
|
78
|
+
`[STORE => ${this.name}] [SET] Creating cronjob for ${key} with '${pattern}' as the pattern and '${timeZone}' for the timezone`
|
79
|
+
);
|
80
|
+
value.job = new Cron(
|
81
|
+
pattern,
|
82
|
+
{
|
83
|
+
name: key,
|
84
|
+
timezone: timeZone,
|
85
|
+
paused: true,
|
86
|
+
// we start the job manually once the client is ready
|
87
|
+
catch: /* @__PURE__ */ __name((error) => {
|
88
|
+
value.error("Encountered an error while running the cron job", error);
|
89
|
+
if (sentry) sentry.captureException(error);
|
90
|
+
}, "catch"),
|
91
|
+
...options
|
92
|
+
},
|
93
|
+
() => {
|
94
|
+
if (sentry) {
|
95
|
+
return sentry.withMonitor(key, () => void value.run.bind(value)(), {
|
96
|
+
schedule: { type: "crontab", value: pattern },
|
97
|
+
timezone: timeZone
|
98
|
+
});
|
99
|
+
}
|
100
|
+
return value.run.bind(value)();
|
101
|
+
}
|
102
|
+
);
|
48
103
|
} catch (error) {
|
49
104
|
value.error("Encountered an error while creating the cron job", error);
|
50
105
|
void value.unload();
|
51
106
|
}
|
52
107
|
return super.set(key, value);
|
53
108
|
}
|
109
|
+
/**
|
110
|
+
* Deletes a task from the store and stops it if it's running.
|
111
|
+
*/
|
54
112
|
delete(key) {
|
55
113
|
const task = this.get(key);
|
56
|
-
if (task
|
114
|
+
if (task && !task.job.isStopped()) {
|
57
115
|
task.job.stop();
|
58
116
|
}
|
59
117
|
return super.delete(key);
|
60
118
|
}
|
61
119
|
/**
|
62
120
|
* Stops all running cron jobs and clears the store.
|
63
|
-
* @returns void
|
64
121
|
*/
|
65
122
|
clear() {
|
66
123
|
this.stopAll();
|
67
124
|
return super.clear();
|
68
125
|
}
|
69
|
-
/**
|
70
|
-
* Formats a Luxon-compatible timezone string into a TZ timezone string.
|
71
|
-
* This is required because Sentry requires time zones to be in TZ format.
|
72
|
-
* @param timezone The Luxon-compatible timezone to format.
|
73
|
-
* @returns The formatted TZ timezone.
|
74
|
-
* @private
|
75
|
-
*/
|
76
|
-
formatLuxonZone(timezone) {
|
77
|
-
const zone = Info.normalizeZone(timezone);
|
78
|
-
if (!zone.isValid) return DateTime.local().zoneName;
|
79
|
-
if (zone instanceof FixedOffsetZone) return zone.ianaName;
|
80
|
-
return zone.name;
|
81
|
-
}
|
82
126
|
};
|
83
127
|
__name(_CronTaskStore, "CronTaskStore");
|
84
128
|
var CronTaskStore = _CronTaskStore;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":[],"mappings":";;;;;AAIO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,KAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,QAAU,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,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAqC,mCAAA,CAAA,CAA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AM,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;AAxIiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.mjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Cron } from 'croner';\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 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, ...options } = value.options;\n\t\tconst { sentry, defaultTimezone } = this.container.cron;\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\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},\n\t\t\t\t\t...options\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tif (sentry) {\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\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"]}
|
package/dist/esm/register.mjs
CHANGED
@@ -14,7 +14,7 @@ var _CronTaskPlugin = class _CronTaskPlugin extends Plugin {
|
|
14
14
|
container.cron.sentry = await import('@sentry/node').catch(() => void 0);
|
15
15
|
}
|
16
16
|
static [postLogin]() {
|
17
|
-
container.cron.
|
17
|
+
container.stores.get("cron-tasks").resumeAll();
|
18
18
|
}
|
19
19
|
};
|
20
20
|
__name(_CronTaskPlugin, "CronTaskPlugin");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuB,MAAO,CAAA;AAAA,EAC1C,QAAwB,yBAAyB,CAAA,CAAwB,OAAwB,EAAA;AAChG,IAAA,SAAA,CAAU,IAAO,GAAA,IAAI,eAAgB,CAAA,OAAA,CAAQ,IAAI,CAAA;AAAA;AAClD,EAEA,QAAw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cAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,cAAe,CAAA,kBAAkB,GAAG,8BAA8B,CAAA;AAExH,cAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,cAAe,CAAA,QAAQ,GAAG,oBAAoB,CAAA;AAE1F,cAAA,CAAe,OAAQ,CAAA,qBAAA,CAAsB,cAAe,CAAA,SAAS,GAAG,qBAAqB,CAAA","file":"register.mjs","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.cron = new CronTaskHandler(options.cron);\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.cron.disableSentry) return;\n\t\tcontainer.cron.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tcontainer.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/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kingsworld/plugin-cron",
|
3
3
|
"description": "A simple @sapphire/framework plugin that aims to make use of the cron package and allow users to make cron jobs within their Sapphire discord bot.",
|
4
|
-
"version": "2.1.2-
|
4
|
+
"version": "2.1.2-pr-102.f10de0b",
|
5
5
|
"author": "Seren_Modz 21 <seren@kings-world.net>",
|
6
6
|
"license": "MIT",
|
7
7
|
"main": "dist/cjs/index.cjs",
|
@@ -46,14 +46,13 @@
|
|
46
46
|
"check-update": "cliff-jumper --dry-run"
|
47
47
|
},
|
48
48
|
"dependencies": {
|
49
|
-
"
|
49
|
+
"croner": "^9.0.0"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
52
|
"@favware/cliff-jumper": "^6.0.0",
|
53
53
|
"@favware/rollup-type-bundler": "^4.0.0",
|
54
|
-
"@sentry/node": "^9.
|
55
|
-
"@types/
|
56
|
-
"@types/node": "^22.13.14",
|
54
|
+
"@sentry/node": "^9.11.0",
|
55
|
+
"@types/node": "^22.14.0",
|
57
56
|
"concurrently": "^9.1.2",
|
58
57
|
"tsup": "^8.4.0",
|
59
58
|
"tsx": "^4.19.3",
|