@kingsworld/plugin-cron 2.0.0-next.179a2eb → 2.0.0-next.29e2862
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/README.md +2 -2
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +6 -104
- package/dist/cjs/lib/CronTaskHandler.cjs +2 -30
- package/dist/cjs/lib/CronTaskHandler.cjs.map +1 -1
- package/dist/cjs/lib/structures/CronTask.cjs +0 -35
- package/dist/cjs/lib/structures/CronTask.cjs.map +1 -1
- package/dist/cjs/lib/structures/CronTaskStore.cjs +0 -13
- package/dist/cjs/lib/structures/CronTaskStore.cjs.map +1 -1
- package/dist/esm/index.d.mts +6 -104
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/CronTaskHandler.mjs +2 -30
- package/dist/esm/lib/CronTaskHandler.mjs.map +1 -1
- package/dist/esm/lib/structures/CronTask.mjs +0 -35
- package/dist/esm/lib/structures/CronTask.mjs.map +1 -1
- package/dist/esm/lib/structures/CronTaskStore.mjs +0 -13
- package/dist/esm/lib/structures/CronTaskStore.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -56,7 +56,7 @@ const options = {
|
|
56
56
|
* The timezone to use for the cron tasks
|
57
57
|
* @default 'UTC'
|
58
58
|
*/
|
59
|
-
|
59
|
+
timeZone: 'Europe/London'
|
60
60
|
}
|
61
61
|
};
|
62
62
|
```
|
@@ -122,7 +122,7 @@ The `CronTask` class provides logging helpers that are similar to the ones provi
|
|
122
122
|
|
123
123
|
This is an example of how to use the `info` helper:
|
124
124
|
|
125
|
-
```
|
125
|
+
```ts
|
126
126
|
import { CronTask } from '@kingsworld/plugin-cron';
|
127
127
|
|
128
128
|
export class PingPong extends CronTask {
|
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.0.0-next.
|
9
|
+
var version = "2.0.0-next.29e2862";
|
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?: 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.0.0-next.
|
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?: 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.0.0-next.29e2862';\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
@@ -7,85 +7,28 @@ interface CronTaskHandlerOptions {
|
|
7
7
|
/**
|
8
8
|
* The default timezone to use for all cron tasks.
|
9
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
10
|
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
12
|
-
* @default
|
11
|
+
* @default "UTC"
|
13
12
|
*/
|
14
|
-
defaultTimezone
|
13
|
+
defaultTimezone?: string;
|
15
14
|
/**
|
16
15
|
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
17
16
|
* If you don't use Sentry, you can ignore this option.
|
18
17
|
* @see https://docs.sentry.io/product/crons/
|
19
|
-
* @default false
|
18
|
+
* @default undefined // technically false
|
20
19
|
*/
|
21
|
-
disableSentry
|
20
|
+
disableSentry?: boolean;
|
22
21
|
}
|
23
22
|
type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
|
24
23
|
|
25
|
-
/**
|
26
|
-
* @example
|
27
|
-
*
|
28
|
-
* ```typescript
|
29
|
-
* // ping.ts
|
30
|
-
* import { CronTask } from '@kingsworld/plugin-cron';
|
31
|
-
*
|
32
|
-
* export class PingPong extends CronTask {
|
33
|
-
* public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
|
34
|
-
* super(context, {
|
35
|
-
* ...options,
|
36
|
-
* cronTime: '* * * * *'
|
37
|
-
* });
|
38
|
-
* }
|
39
|
-
*
|
40
|
-
* public run() {
|
41
|
-
* this.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓
|
42
|
-
* }
|
43
|
-
* }
|
44
|
-
* ```
|
45
|
-
*/
|
46
24
|
declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
|
47
25
|
job: CronJob<null, CronTask>;
|
48
26
|
constructor(context: CronTask.LoaderContext, options: Options);
|
49
27
|
abstract run(): Awaitable<unknown>;
|
50
|
-
/**
|
51
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
52
|
-
* @param message The message to include after the prefix
|
53
|
-
* @param other Extra parameters to pass to the logger
|
54
|
-
* @example
|
55
|
-
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
56
|
-
*/
|
57
28
|
info(message: string, ...other: unknown[]): void;
|
58
|
-
/**
|
59
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
60
|
-
* @param message The message to include after the prefix
|
61
|
-
* @param other Extra parameters to pass to the logger
|
62
|
-
* @example
|
63
|
-
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
64
|
-
*/
|
65
29
|
error(message: string, ...other: unknown[]): void;
|
66
|
-
/**
|
67
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
68
|
-
* @param message The message to include after the prefix
|
69
|
-
* @param other Extra parameters to pass to the logger
|
70
|
-
* @example
|
71
|
-
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
72
|
-
*/
|
73
30
|
warn(message: string, ...other: unknown[]): void;
|
74
|
-
/**
|
75
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
76
|
-
* @param message The message to include after the prefix
|
77
|
-
* @param other Extra parameters to pass to the logger
|
78
|
-
* @example
|
79
|
-
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
80
|
-
*/
|
81
31
|
debug(message: string, ...other: unknown[]): void;
|
82
|
-
/**
|
83
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
84
|
-
* @param message The message to include after the prefix
|
85
|
-
* @param other Extra parameters to pass to the logger
|
86
|
-
* @example
|
87
|
-
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
88
|
-
*/
|
89
32
|
trace(message: string, ...other: unknown[]): void;
|
90
33
|
}
|
91
34
|
declare namespace CronTask {
|
@@ -97,61 +40,20 @@ declare namespace CronTask {
|
|
97
40
|
|
98
41
|
declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
|
99
42
|
constructor();
|
100
|
-
/**
|
101
|
-
* Loops over all tasks and starts those that are enabled.
|
102
|
-
* This gets called automatically when the Client is ready.
|
103
|
-
* @returns CronTaskStore
|
104
|
-
*/
|
105
43
|
startAll(): this;
|
106
|
-
/**
|
107
|
-
* Loops over all tasks and stops those that are running.
|
108
|
-
* @returns CronTaskStore
|
109
|
-
*/
|
110
44
|
stopAll(): this;
|
111
45
|
set(key: string, value: CronTask): this;
|
112
46
|
delete(key: string): boolean;
|
113
|
-
/**
|
114
|
-
* Stops all running cron jobs and clears the store.
|
115
|
-
* @returns void
|
116
|
-
*/
|
117
47
|
clear(): void;
|
118
48
|
}
|
119
49
|
|
120
50
|
declare class CronTaskHandler {
|
121
|
-
|
122
|
-
|
123
|
-
* You can override this per task, using the timeZone option.
|
124
|
-
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
125
|
-
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
126
|
-
* @default 'UTC'
|
127
|
-
*/
|
128
|
-
defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];
|
129
|
-
/**
|
130
|
-
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
131
|
-
* If you don't use Sentry, you can ignore this option.
|
132
|
-
* @see https://docs.sentry.io/product/crons/
|
133
|
-
* @default false
|
134
|
-
*/
|
135
|
-
disableSentry: boolean;
|
136
|
-
/**
|
137
|
-
* The Sentry instance to use for instrumenting cron jobs.
|
138
|
-
* This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
|
139
|
-
* is installed and the {@linkcode disableSentry} option is set to false.
|
140
|
-
*/
|
51
|
+
defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];
|
52
|
+
disableSentry?: boolean;
|
141
53
|
sentry?: typeof Sentry;
|
142
54
|
constructor(options?: CronTaskHandlerOptions);
|
143
|
-
/**
|
144
|
-
* Start all enabled cron jobs.
|
145
|
-
* This gets called automatically when the Client is ready.
|
146
|
-
*/
|
147
55
|
startAll(): void;
|
148
|
-
/**
|
149
|
-
* Stop all running cron jobs.
|
150
|
-
*/
|
151
56
|
stopAll(): void;
|
152
|
-
/**
|
153
|
-
* Get the cron task store.
|
154
|
-
*/
|
155
57
|
private get store();
|
156
58
|
}
|
157
59
|
|
@@ -8,46 +8,18 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
8
8
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
9
9
|
var _CronTaskHandler = class _CronTaskHandler {
|
10
10
|
constructor(options) {
|
11
|
-
/**
|
12
|
-
* The default timezone to use for all cron tasks.
|
13
|
-
* You can override this per task, using the timeZone option.
|
14
|
-
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
15
|
-
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
16
|
-
* @default 'UTC'
|
17
|
-
*/
|
18
11
|
__publicField(this, "defaultTimezone");
|
19
|
-
/**
|
20
|
-
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
21
|
-
* If you don't use Sentry, you can ignore this option.
|
22
|
-
* @see https://docs.sentry.io/product/crons/
|
23
|
-
* @default false
|
24
|
-
*/
|
25
12
|
__publicField(this, "disableSentry");
|
26
|
-
/**
|
27
|
-
* The Sentry instance to use for instrumenting cron jobs.
|
28
|
-
* This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
|
29
|
-
* is installed and the {@linkcode disableSentry} option is set to false.
|
30
|
-
*/
|
31
13
|
__publicField(this, "sentry");
|
32
|
-
this.defaultTimezone = options?.defaultTimezone
|
33
|
-
this.disableSentry = options?.disableSentry
|
14
|
+
this.defaultTimezone = options?.defaultTimezone;
|
15
|
+
this.disableSentry = options?.disableSentry;
|
34
16
|
}
|
35
|
-
/**
|
36
|
-
* Start all enabled cron jobs.
|
37
|
-
* This gets called automatically when the Client is ready.
|
38
|
-
*/
|
39
17
|
startAll() {
|
40
18
|
this.store.startAll();
|
41
19
|
}
|
42
|
-
/**
|
43
|
-
* Stop all running cron jobs.
|
44
|
-
*/
|
45
20
|
stopAll() {
|
46
21
|
this.store.stopAll();
|
47
22
|
}
|
48
|
-
/**
|
49
|
-
* Get the cron task store.
|
50
|
-
*/
|
51
23
|
get store() {
|
52
24
|
return framework.container.stores.get("cron-tasks");
|
53
25
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":["container"],"mappings":";;;;;;;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,
|
1
|
+
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":["container"],"mappings":";;;;;;;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAKrB,YAAY,OAAkC,EAAA;AAJrD,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AACP,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AACP,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAS,EAAA,eAAA,CAAA;AAChC,IAAA,IAAA,CAAK,gBAAgB,OAAS,EAAA,aAAA,CAAA;AAAA,GAC/B;AAAA,EAEO,QAAW,GAAA;AACjB,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACrB;AAAA,EAEO,OAAU,GAAA;AAChB,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACpB;AAAA,EAEA,IAAY,KAAQ,GAAA;AACnB,IAAO,OAAAA,mBAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GACzC;AACD,CAAA,CAAA;AArB6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.cjs","sourcesContent":["import { container } from '@sapphire/framework';\nimport type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\tpublic defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];\n\tpublic disableSentry?: boolean;\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: CronTaskHandlerOptions) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry;\n\t}\n\n\tpublic startAll() {\n\t\tthis.store.startAll();\n\t}\n\n\tpublic stopAll() {\n\t\tthis.store.stopAll();\n\t}\n\n\tprivate get store() {\n\t\treturn container.stores.get('cron-tasks');\n\t}\n}\n"]}
|
@@ -8,53 +8,18 @@ var _CronTask = class _CronTask extends pieces.Piece {
|
|
8
8
|
constructor(context, options) {
|
9
9
|
super(context, options);
|
10
10
|
}
|
11
|
-
/**
|
12
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
13
|
-
* @param message The message to include after the prefix
|
14
|
-
* @param other Extra parameters to pass to the logger
|
15
|
-
* @example
|
16
|
-
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
17
|
-
*/
|
18
11
|
info(message, ...other) {
|
19
12
|
this.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);
|
20
13
|
}
|
21
|
-
/**
|
22
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
23
|
-
* @param message The message to include after the prefix
|
24
|
-
* @param other Extra parameters to pass to the logger
|
25
|
-
* @example
|
26
|
-
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
27
|
-
*/
|
28
14
|
error(message, ...other) {
|
29
15
|
this.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);
|
30
16
|
}
|
31
|
-
/**
|
32
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
33
|
-
* @param message The message to include after the prefix
|
34
|
-
* @param other Extra parameters to pass to the logger
|
35
|
-
* @example
|
36
|
-
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
37
|
-
*/
|
38
17
|
warn(message, ...other) {
|
39
18
|
this.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);
|
40
19
|
}
|
41
|
-
/**
|
42
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
43
|
-
* @param message The message to include after the prefix
|
44
|
-
* @param other Extra parameters to pass to the logger
|
45
|
-
* @example
|
46
|
-
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
47
|
-
*/
|
48
20
|
debug(message, ...other) {
|
49
21
|
this.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);
|
50
22
|
}
|
51
|
-
/**
|
52
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
53
|
-
* @param message The message to include after the prefix
|
54
|
-
* @param other Extra parameters to pass to the logger
|
55
|
-
* @example
|
56
|
-
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
57
|
-
*/
|
58
23
|
trace(message, ...other) {
|
59
24
|
this.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);
|
60
25
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":["Piece"],"mappings":";;;;;;
|
1
|
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AA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AACD,CAAA,CAAA;AA5ByH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.cjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { CronJob } from 'cron';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\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\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\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"]}
|
@@ -10,11 +10,6 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
10
10
|
constructor() {
|
11
11
|
super(CronTask_cjs.CronTask, { name: "cron-tasks" });
|
12
12
|
}
|
13
|
-
/**
|
14
|
-
* Loops over all tasks and starts those that are enabled.
|
15
|
-
* This gets called automatically when the Client is ready.
|
16
|
-
* @returns CronTaskStore
|
17
|
-
*/
|
18
13
|
startAll() {
|
19
14
|
for (const task of this.values()) {
|
20
15
|
if (!task.enabled) continue;
|
@@ -23,10 +18,6 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
23
18
|
pieces.Store.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);
|
24
19
|
return this;
|
25
20
|
}
|
26
|
-
/**
|
27
|
-
* Loops over all tasks and stops those that are running.
|
28
|
-
* @returns CronTaskStore
|
29
|
-
*/
|
30
21
|
stopAll() {
|
31
22
|
for (const task of this.values()) {
|
32
23
|
if (!task.job.running) continue;
|
@@ -60,10 +51,6 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
60
51
|
}
|
61
52
|
return super.delete(key);
|
62
53
|
}
|
63
|
-
/**
|
64
|
-
* Stops all running cron jobs and clears the store.
|
65
|
-
* @returns void
|
66
|
-
*/
|
67
54
|
clear() {
|
68
55
|
this.stopAll();
|
69
56
|
return super.clear();
|
@@ -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
|
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;AA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AAA,QACP,OAAS,EAAA,KAAA;AAAA,QACT,QAAA,EAAU,QAAQ,QAAY,IAAA,eAAA;AAAA,OAC9B,CAAA,CAAA;AAAA,aACO,KAAO,EAAA;AACf,MAAM,KAAA,CAAA,KAAA,CAAM,oDAAoD,KAAK,CAAA,CAAA;AACrE,MAAA,KAAK,MAAM,MAAO,EAAA,CAAA;AAAA,KACnB;AAEA,IAAO,OAAA,KAAA,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,EAEgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA,CAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AA5DiE,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\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\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\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
|
package/dist/esm/index.d.mts
CHANGED
@@ -7,85 +7,28 @@ interface CronTaskHandlerOptions {
|
|
7
7
|
/**
|
8
8
|
* The default timezone to use for all cron tasks.
|
9
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
10
|
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
12
|
-
* @default
|
11
|
+
* @default "UTC"
|
13
12
|
*/
|
14
|
-
defaultTimezone
|
13
|
+
defaultTimezone?: string;
|
15
14
|
/**
|
16
15
|
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
17
16
|
* If you don't use Sentry, you can ignore this option.
|
18
17
|
* @see https://docs.sentry.io/product/crons/
|
19
|
-
* @default false
|
18
|
+
* @default undefined // technically false
|
20
19
|
*/
|
21
|
-
disableSentry
|
20
|
+
disableSentry?: boolean;
|
22
21
|
}
|
23
22
|
type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
|
24
23
|
|
25
|
-
/**
|
26
|
-
* @example
|
27
|
-
*
|
28
|
-
* ```typescript
|
29
|
-
* // ping.ts
|
30
|
-
* import { CronTask } from '@kingsworld/plugin-cron';
|
31
|
-
*
|
32
|
-
* export class PingPong extends CronTask {
|
33
|
-
* public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
|
34
|
-
* super(context, {
|
35
|
-
* ...options,
|
36
|
-
* cronTime: '* * * * *'
|
37
|
-
* });
|
38
|
-
* }
|
39
|
-
*
|
40
|
-
* public run() {
|
41
|
-
* this.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓
|
42
|
-
* }
|
43
|
-
* }
|
44
|
-
* ```
|
45
|
-
*/
|
46
24
|
declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
|
47
25
|
job: CronJob<null, CronTask>;
|
48
26
|
constructor(context: CronTask.LoaderContext, options: Options);
|
49
27
|
abstract run(): Awaitable<unknown>;
|
50
|
-
/**
|
51
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
52
|
-
* @param message The message to include after the prefix
|
53
|
-
* @param other Extra parameters to pass to the logger
|
54
|
-
* @example
|
55
|
-
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
56
|
-
*/
|
57
28
|
info(message: string, ...other: unknown[]): void;
|
58
|
-
/**
|
59
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
60
|
-
* @param message The message to include after the prefix
|
61
|
-
* @param other Extra parameters to pass to the logger
|
62
|
-
* @example
|
63
|
-
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
64
|
-
*/
|
65
29
|
error(message: string, ...other: unknown[]): void;
|
66
|
-
/**
|
67
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
68
|
-
* @param message The message to include after the prefix
|
69
|
-
* @param other Extra parameters to pass to the logger
|
70
|
-
* @example
|
71
|
-
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
72
|
-
*/
|
73
30
|
warn(message: string, ...other: unknown[]): void;
|
74
|
-
/**
|
75
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
76
|
-
* @param message The message to include after the prefix
|
77
|
-
* @param other Extra parameters to pass to the logger
|
78
|
-
* @example
|
79
|
-
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
80
|
-
*/
|
81
31
|
debug(message: string, ...other: unknown[]): void;
|
82
|
-
/**
|
83
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
84
|
-
* @param message The message to include after the prefix
|
85
|
-
* @param other Extra parameters to pass to the logger
|
86
|
-
* @example
|
87
|
-
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
88
|
-
*/
|
89
32
|
trace(message: string, ...other: unknown[]): void;
|
90
33
|
}
|
91
34
|
declare namespace CronTask {
|
@@ -97,61 +40,20 @@ declare namespace CronTask {
|
|
97
40
|
|
98
41
|
declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
|
99
42
|
constructor();
|
100
|
-
/**
|
101
|
-
* Loops over all tasks and starts those that are enabled.
|
102
|
-
* This gets called automatically when the Client is ready.
|
103
|
-
* @returns CronTaskStore
|
104
|
-
*/
|
105
43
|
startAll(): this;
|
106
|
-
/**
|
107
|
-
* Loops over all tasks and stops those that are running.
|
108
|
-
* @returns CronTaskStore
|
109
|
-
*/
|
110
44
|
stopAll(): this;
|
111
45
|
set(key: string, value: CronTask): this;
|
112
46
|
delete(key: string): boolean;
|
113
|
-
/**
|
114
|
-
* Stops all running cron jobs and clears the store.
|
115
|
-
* @returns void
|
116
|
-
*/
|
117
47
|
clear(): void;
|
118
48
|
}
|
119
49
|
|
120
50
|
declare class CronTaskHandler {
|
121
|
-
|
122
|
-
|
123
|
-
* You can override this per task, using the timeZone option.
|
124
|
-
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
125
|
-
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
126
|
-
* @default 'UTC'
|
127
|
-
*/
|
128
|
-
defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];
|
129
|
-
/**
|
130
|
-
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
131
|
-
* If you don't use Sentry, you can ignore this option.
|
132
|
-
* @see https://docs.sentry.io/product/crons/
|
133
|
-
* @default false
|
134
|
-
*/
|
135
|
-
disableSentry: boolean;
|
136
|
-
/**
|
137
|
-
* The Sentry instance to use for instrumenting cron jobs.
|
138
|
-
* This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
|
139
|
-
* is installed and the {@linkcode disableSentry} option is set to false.
|
140
|
-
*/
|
51
|
+
defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];
|
52
|
+
disableSentry?: boolean;
|
141
53
|
sentry?: typeof Sentry;
|
142
54
|
constructor(options?: CronTaskHandlerOptions);
|
143
|
-
/**
|
144
|
-
* Start all enabled cron jobs.
|
145
|
-
* This gets called automatically when the Client is ready.
|
146
|
-
*/
|
147
55
|
startAll(): void;
|
148
|
-
/**
|
149
|
-
* Stop all running cron jobs.
|
150
|
-
*/
|
151
56
|
stopAll(): void;
|
152
|
-
/**
|
153
|
-
* Get the cron task store.
|
154
|
-
*/
|
155
57
|
private get store();
|
156
58
|
}
|
157
59
|
|
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.0.0-next.
|
7
|
+
var version = "2.0.0-next.29e2862";
|
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?: 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.0.0-next.
|
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 = '2.0.0-next.29e2862';\n"]}
|
@@ -3,46 +3,18 @@ import { container } from '@sapphire/framework';
|
|
3
3
|
|
4
4
|
var _CronTaskHandler = class _CronTaskHandler {
|
5
5
|
constructor(options) {
|
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
|
-
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
11
|
-
* @default 'UTC'
|
12
|
-
*/
|
13
6
|
__publicField(this, "defaultTimezone");
|
14
|
-
/**
|
15
|
-
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
16
|
-
* If you don't use Sentry, you can ignore this option.
|
17
|
-
* @see https://docs.sentry.io/product/crons/
|
18
|
-
* @default false
|
19
|
-
*/
|
20
7
|
__publicField(this, "disableSentry");
|
21
|
-
/**
|
22
|
-
* The Sentry instance to use for instrumenting cron jobs.
|
23
|
-
* This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
|
24
|
-
* is installed and the {@linkcode disableSentry} option is set to false.
|
25
|
-
*/
|
26
8
|
__publicField(this, "sentry");
|
27
|
-
this.defaultTimezone = options?.defaultTimezone
|
28
|
-
this.disableSentry = options?.disableSentry
|
9
|
+
this.defaultTimezone = options?.defaultTimezone;
|
10
|
+
this.disableSentry = options?.disableSentry;
|
29
11
|
}
|
30
|
-
/**
|
31
|
-
* Start all enabled cron jobs.
|
32
|
-
* This gets called automatically when the Client is ready.
|
33
|
-
*/
|
34
12
|
startAll() {
|
35
13
|
this.store.startAll();
|
36
14
|
}
|
37
|
-
/**
|
38
|
-
* Stop all running cron jobs.
|
39
|
-
*/
|
40
15
|
stopAll() {
|
41
16
|
this.store.stopAll();
|
42
17
|
}
|
43
|
-
/**
|
44
|
-
* Get the cron task store.
|
45
|
-
*/
|
46
18
|
get store() {
|
47
19
|
return container.stores.get("cron-tasks");
|
48
20
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,
|
1
|
+
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAKrB,YAAY,OAAkC,EAAA;AAJrD,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AACP,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AACP,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAS,EAAA,eAAA,CAAA;AAChC,IAAA,IAAA,CAAK,gBAAgB,OAAS,EAAA,aAAA,CAAA;AAAA,GAC/B;AAAA,EAEO,QAAW,GAAA;AACjB,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACrB;AAAA,EAEO,OAAU,GAAA;AAChB,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACpB;AAAA,EAEA,IAAY,KAAQ,GAAA;AACnB,IAAO,OAAA,SAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GACzC;AACD,CAAA,CAAA;AArB6B,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\tpublic defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];\n\tpublic disableSentry?: boolean;\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: CronTaskHandlerOptions) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry;\n\t}\n\n\tpublic startAll() {\n\t\tthis.store.startAll();\n\t}\n\n\tpublic stopAll() {\n\t\tthis.store.stopAll();\n\t}\n\n\tprivate get store() {\n\t\treturn container.stores.get('cron-tasks');\n\t}\n}\n"]}
|
@@ -5,53 +5,18 @@ var _CronTask = class _CronTask extends Piece {
|
|
5
5
|
constructor(context, options) {
|
6
6
|
super(context, options);
|
7
7
|
}
|
8
|
-
/**
|
9
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
10
|
-
* @param message The message to include after the prefix
|
11
|
-
* @param other Extra parameters to pass to the logger
|
12
|
-
* @example
|
13
|
-
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
14
|
-
*/
|
15
8
|
info(message, ...other) {
|
16
9
|
this.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);
|
17
10
|
}
|
18
|
-
/**
|
19
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
20
|
-
* @param message The message to include after the prefix
|
21
|
-
* @param other Extra parameters to pass to the logger
|
22
|
-
* @example
|
23
|
-
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
24
|
-
*/
|
25
11
|
error(message, ...other) {
|
26
12
|
this.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);
|
27
13
|
}
|
28
|
-
/**
|
29
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
30
|
-
* @param message The message to include after the prefix
|
31
|
-
* @param other Extra parameters to pass to the logger
|
32
|
-
* @example
|
33
|
-
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
34
|
-
*/
|
35
14
|
warn(message, ...other) {
|
36
15
|
this.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);
|
37
16
|
}
|
38
|
-
/**
|
39
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
40
|
-
* @param message The message to include after the prefix
|
41
|
-
* @param other Extra parameters to pass to the logger
|
42
|
-
* @example
|
43
|
-
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
44
|
-
*/
|
45
17
|
debug(message, ...other) {
|
46
18
|
this.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);
|
47
19
|
}
|
48
|
-
/**
|
49
|
-
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
50
|
-
* @param message The message to include after the prefix
|
51
|
-
* @param other Extra parameters to pass to the logger
|
52
|
-
* @example
|
53
|
-
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
54
|
-
*/
|
55
20
|
trace(message, ...other) {
|
56
21
|
this.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);
|
57
22
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;AAKO,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,EAIO,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,EAEO,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,EAEO,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,EAEO,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,EAEO,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;AA5ByH,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\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\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\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"]}
|
@@ -7,11 +7,6 @@ var _CronTaskStore = class _CronTaskStore extends Store {
|
|
7
7
|
constructor() {
|
8
8
|
super(CronTask, { name: "cron-tasks" });
|
9
9
|
}
|
10
|
-
/**
|
11
|
-
* Loops over all tasks and starts those that are enabled.
|
12
|
-
* This gets called automatically when the Client is ready.
|
13
|
-
* @returns CronTaskStore
|
14
|
-
*/
|
15
10
|
startAll() {
|
16
11
|
for (const task of this.values()) {
|
17
12
|
if (!task.enabled) continue;
|
@@ -20,10 +15,6 @@ var _CronTaskStore = class _CronTaskStore extends Store {
|
|
20
15
|
Store.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);
|
21
16
|
return this;
|
22
17
|
}
|
23
|
-
/**
|
24
|
-
* Loops over all tasks and stops those that are running.
|
25
|
-
* @returns CronTaskStore
|
26
|
-
*/
|
27
18
|
stopAll() {
|
28
19
|
for (const task of this.values()) {
|
29
20
|
if (!task.job.running) continue;
|
@@ -57,10 +48,6 @@ var _CronTaskStore = class _CronTaskStore extends Store {
|
|
57
48
|
}
|
58
49
|
return super.delete(key);
|
59
50
|
}
|
60
|
-
/**
|
61
|
-
* Stops all running cron jobs and clears the store.
|
62
|
-
* @returns void
|
63
|
-
*/
|
64
51
|
clear() {
|
65
52
|
this.stopAll();
|
66
53
|
return super.clear();
|
@@ -1 +1 @@
|
|
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,CAAA;AAAA,GACvC;AAAA
|
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,CAAA;AAAA,GACvC;AAAA,EAEO,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,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAsC,oCAAA,CAAA,CAAA,CAAA;AAC3E,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA,EAEO,OAAU,GAAA;AAChB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,IAAK,CAAA,GAAA,CAAI,OAAS,EAAA,SAAA;AACvB,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA,CAAA;AAAA,KACf;AAEA,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAqC,mCAAA,CAAA,CAAA,CAAA;AAC1E,IAAO,OAA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,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AA5DiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.mjs","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\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\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\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\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.0.0-next.
|
4
|
+
"version": "2.0.0-next.29e2862",
|
5
5
|
"author": "Seren_Modz 21 <seren@kings-world.net>",
|
6
6
|
"license": "MIT",
|
7
7
|
"main": "dist/cjs/index.cjs",
|