@kingsworld/plugin-cron 3.0.1-next.e1b3c15 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,51 +2,85 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- # [@kingsworld/plugin-cron@3.0.0](https://github.com/Kings-World/sapphire-plugins/tree/@kingsworld/plugin-cron@3.0.0) - (2024-09-12)
5
+ # [@kingsworld/plugin-cron@3.0.1](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.1.1...@kingsworld/plugin-cron@3.0.1) - (2025-04-07)
6
6
 
7
7
  ## 🏠 Refactor
8
8
 
9
- - Set option defaults and add more js docs ([179a2eb](https://github.com/Kings-World/sapphire-plugins/commit/179a2ebac74a3b2ded82500b8c8c6425f8af1e0f)) ([#35](https://github.com/Kings-World/sapphire-plugins/pull/35) by @SerenModz21)
10
- - Improve the repo ([3546f66](https://github.com/Kings-World/sapphire-plugins/commit/3546f669d767764b622310dbf679ca8c86abfea6)) ([#26](https://github.com/Kings-World/sapphire-plugins/pull/26) by @Swiizyy)
11
- - Switch to sapphire v5 changes ([3fcbf9e](https://github.com/Kings-World/sapphire-plugins/commit/3fcbf9ef0f541c4155875c38b406f5a1872f9de6))
9
+ - **cron:** Replace the cron package with croner ([efd4ebb](https://github.com/Kings-World/sapphire-plugins/commit/efd4ebbd2e38f106bc322ffb962c5dcccb503c63)) ([#102](https://github.com/Kings-World/sapphire-plugins/pull/102) by @SerenModz21)
12
10
  - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
13
- - Update to sapphire v5 ([61e68a9](https://github.com/Kings-World/sapphire-plugins/commit/61e68a983eeb2d3c5334217930114a9cf08dafe7))
14
- - Switch to a monorepo ([7646fbb](https://github.com/Kings-World/sapphire-plugins/commit/7646fbb4ace71e7d3e939a29b89c72d213da36ce))
15
- - 💥 **BREAKING CHANGE:** move to a monorepo
16
11
 
17
- ## 🐛 Bug Fixes
12
+ * refactor: replace cron with croner
13
+ - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
18
14
 
19
- - **cron:** Correct the cliff jumper org ([b7ee600](https://github.com/Kings-World/sapphire-plugins/commit/b7ee6007cca0d372edc27997268ec45db14304ac))
20
- - Use luxon's system default instead of utc ([b56bf6b](https://github.com/Kings-World/sapphire-plugins/commit/b56bf6b9889ddf3c46f069fdf93043f074a16462)) ([#38](https://github.com/Kings-World/sapphire-plugins/pull/38) by @SerenModz21)
21
- - Use the default export and actually register the hook ([5e271bf](https://github.com/Kings-World/sapphire-plugins/commit/5e271bfceb335be3e709831c9fad46c05f75b309))
22
- - Ensure cts file extensions in dist/cjs ([907123a](https://github.com/Kings-World/sapphire-plugins/commit/907123a017210d3acca81f3373cbe5a3c102261f))
23
- - Move readme ([e1c1f2d](https://github.com/Kings-World/sapphire-plugins/commit/e1c1f2d2b0a087489364db49b783de243af63244))
15
+ * refactor: replace cron with croner
16
+ - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
24
17
 
25
- ## 📝 Documentation
18
+ * style: rename cron to cronTasks
19
+ - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
26
20
 
27
- - **cron:** Add public keyword for consistency ([7e098d9](https://github.com/Kings-World/sapphire-plugins/commit/7e098d99437ad4b671c4e559f3532ce33a51d5ee))
28
- - **cron:** Fix plugin name ([bea107d](https://github.com/Kings-World/sapphire-plugins/commit/bea107d72fdb86f42845bfa51cd02e8c6c8690a3))
29
- - **cron:** Improve readme ([ede60d2](https://github.com/Kings-World/sapphire-plugins/commit/ede60d209d13af296507407675543ad7c05c4410)) ([#27](https://github.com/Kings-World/sapphire-plugins/pull/27) by @Swiizyy)
30
- - Improve the readme ([784b306](https://github.com/Kings-World/sapphire-plugins/commit/784b306295c815bfc824b0143dd8b3f98a705afc))
31
- - Fix package misspelling in readme ([6106d42](https://github.com/Kings-World/sapphire-plugins/commit/6106d42f6c98f28e9abdec70628d128cbcffc5d1))
32
- - Update context type in readme ([be0102e](https://github.com/Kings-World/sapphire-plugins/commit/be0102e816d7c711d0d531cd96eb0f9b64bab794))
33
- - Fix the in spelling ([3f71cf9](https://github.com/Kings-World/sapphire-plugins/commit/3f71cf92f6c0b2c2d00fbe20ac35d362d9b84bb9))
34
- - Fix plugin spelling ([6b395bd](https://github.com/Kings-World/sapphire-plugins/commit/6b395bd82affef3ae0be9aeb2653cc5b31ca339d))
35
- - Fix incorrect word ([0149312](https://github.com/Kings-World/sapphire-plugins/commit/0149312285fd839ccbecd3f1f7ecfb39699ea97a))
36
- - Finish contributing section and update repo name ([7b73668](https://github.com/Kings-World/sapphire-plugins/commit/7b7366865a376cf2e070359342505606e531b737))
21
+ * docs: update documentation
22
+ - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
23
+
24
+ * refactor: use this.stores instead of container.stores
25
+ - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
26
+
27
+ * feat: add protect and catch methods for additional logic
28
+ - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
29
+
30
+ * refactor: normalize pattern for sentry and prevent dates or iso string from being monitored
31
+ - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
32
+
33
+ * refactor: update version
34
+
35
+ i accidentally publish 3.0.0 by accident when i was new to using cliff-jumper
36
+
37
+ therefore, i have to skip that and go straight to 3.0.1
38
+ - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
39
+
40
+ ---------
41
+ - 💥 **BREAKING CHANGE:** The `cronTime` option has been replaced with `pattern`.
42
+ - 💥 **BREAKING CHANGE:** The `timeZone` option has been replaced with `timezone`.
43
+ - 💥 **BREAKING CHANGE:** The `cron` package has been replaced with `croner`.
44
+ - 💥 **BREAKING CHANGE:** `container.cron.startAll()` and `container.cron.stopAll()` have been removed. Instead, you should pause and resume using the plugin's store.
45
+ - 💥 **BREAKING CHANGE:** References to the word `cron` have been replaced with `cronTasks` for consistency. For example, `container.cron` is now `container.cronTasks` and `ClientOptions.cron` is now `ClientOptions.cronTasks`.
46
+ - 💥 **Signed-off-by:** Seren_Modz 21 <seren@kings-world.net>
47
+ - Add the override keyword to the plugin methods ([a581de3](https://github.com/Kings-World/sapphire-plugins/commit/a581de3ae477d1f5fcff5e8376fb7c60fdae7daa))
48
+
49
+ # [@kingsworld/plugin-cron@2.1.1](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.1.0...@kingsworld/plugin-cron@2.1.1) - (2025-04-05)
50
+
51
+ ## 🐛 Bug Fixes
52
+
53
+ - **deps:** Update all non-major dependencies ([83f972e](https://github.com/Kings-World/sapphire-plugins/commit/83f972eda0f3db62cfab8916e5c444abc0247e10)) ([#97](https://github.com/Kings-World/sapphire-plugins/pull/97) by @renovate[bot])
54
+ - **deps:** Update dependency cron to v4 ([1550eff](https://github.com/Kings-World/sapphire-plugins/commit/1550eff0705e5430281291aeb0fe18a830186915)) ([#91](https://github.com/Kings-World/sapphire-plugins/pull/91) by @renovate[bot])
55
+ - **deps:** Update all non-major dependencies ([d5bd44f](https://github.com/Kings-World/sapphire-plugins/commit/d5bd44fbbe46d8aaa92b6157dccb9536debc66a0)) ([#80](https://github.com/Kings-World/sapphire-plugins/pull/80) by @renovate[bot])
56
+ - **deps:** Update all non-major dependencies ([fab1c9f](https://github.com/Kings-World/sapphire-plugins/commit/fab1c9f661175bc9c2fdfc7d9ab3af59d16acc6f)) ([#79](https://github.com/Kings-World/sapphire-plugins/pull/79) by @renovate[bot])
57
+ - **deps:** Update all non-major dependencies ([e44b9ef](https://github.com/Kings-World/sapphire-plugins/commit/e44b9efa5b164699dd4393188c38e6f3fdadcc3e)) ([#75](https://github.com/Kings-World/sapphire-plugins/pull/75) by @renovate[bot])
58
+
59
+ # [@kingsworld/plugin-cron@2.1.0](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.0.3...@kingsworld/plugin-cron@2.1.0) - (2024-10-03)
37
60
 
38
61
  ## 🚀 Features
39
62
 
40
- - Allow disabling sentry instrumention and import automatically ([935821f](https://github.com/Kings-World/sapphire-plugins/commit/935821f4ed990ef97c3beb58901dbe96281da020))
41
- - Add optional support for sentry's cron & add jsdoc ([555b5ae](https://github.com/Kings-World/sapphire-plugins/commit/555b5ae47535b06f5730dacdf041d38b01deda52))
42
- - Update dependencies and release 1.1.0 ([b1aead8](https://github.com/Kings-World/sapphire-plugins/commit/b1aead83ba6ebd781c4bde554a8a3a459f6415c9))
63
+ - Format luxon timezones to their tz identifier ([47cb7ef](https://github.com/Kings-World/sapphire-plugins/commit/47cb7ef6970ae6255fe068f2f5cec1ace1ed8109)) ([#49](https://github.com/Kings-World/sapphire-plugins/pull/49) by @SerenModz21)
43
64
 
44
- ## 🪞 Styling
65
+ # [@kingsworld/plugin-cron@2.0.3](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.0.2...@kingsworld/plugin-cron@2.0.3) - (2024-09-27)
45
66
 
46
- - Format readme ([7b1c49f](https://github.com/Kings-World/sapphire-plugins/commit/7b1c49fbfaa85f45264f3028da663fcfb87ef826))
47
- - Format everything ([e7ba3e2](https://github.com/Kings-World/sapphire-plugins/commit/e7ba3e2810e80382c4bf4e95e8fdc3d3868aab95))
67
+ ## 🐛 Bug Fixes
68
+
69
+ - **cron:** Correctly handle the sentry import ([c596f64](https://github.com/Kings-World/sapphire-plugins/commit/c596f64b2ae233ad2be5e02d3c68aa30329c88ce)) ([#47](https://github.com/Kings-World/sapphire-plugins/pull/47) by @SerenModz21)
48
70
 
49
- # [@Kings-World/plugin-cron@2.0.0](https://github.com/Kings-World/sapphire-plugins/tree/@Kings-World/plugin-cron@2.0.0) - (2024-09-12)
71
+ # [@kingsworld/plugin-cron@2.0.2](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.0.1...@kingsworld/plugin-cron@2.0.2) - (2024-09-15)
72
+
73
+ ## 🐛 Bug Fixes
74
+
75
+ - The ClientOptions#cron also needs to be partial ([f31d23a](https://github.com/Kings-World/sapphire-plugins/commit/f31d23a39187b2fc901c9d83723efafcd6942b4d)) ([#44](https://github.com/Kings-World/sapphire-plugins/pull/44) by @SerenModz21)
76
+
77
+ # [@kingsworld/plugin-cron@2.0.1](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.0.0...@kingsworld/plugin-cron@2.0.1) - (2024-09-15)
78
+
79
+ ## 🐛 Bug Fixes
80
+
81
+ - Use the partial helper to make options optional ([fa10a8a](https://github.com/Kings-World/sapphire-plugins/commit/fa10a8a072354362a5816323b5c66ff6ace97b9d)) ([#43](https://github.com/Kings-World/sapphire-plugins/pull/43) by @SerenModz21)
82
+
83
+ # [@kingsworld/plugin-cron@2.0.0](https://github.com/Kings-World/sapphire-plugins/tree/@kingsworld/plugin-cron@2.0.0) - (2024-09-12)
50
84
 
51
85
  ## 🏠 Refactor
52
86
 
@@ -60,6 +94,7 @@ All notable changes to this project will be documented in this file.
60
94
 
61
95
  ## 🐛 Bug Fixes
62
96
 
97
+ - **cron:** Correct the cliff jumper org ([b7ee600](https://github.com/Kings-World/sapphire-plugins/commit/b7ee6007cca0d372edc27997268ec45db14304ac))
63
98
  - Use luxon's system default instead of utc ([b56bf6b](https://github.com/Kings-World/sapphire-plugins/commit/b56bf6b9889ddf3c46f069fdf93043f074a16462)) ([#38](https://github.com/Kings-World/sapphire-plugins/pull/38) by @SerenModz21)
64
99
  - Use the default export and actually register the hook ([5e271bf](https://github.com/Kings-World/sapphire-plugins/commit/5e271bfceb335be3e709831c9fad46c05f75b309))
65
100
  - Ensure cts file extensions in dist/cjs ([907123a](https://github.com/Kings-World/sapphire-plugins/commit/907123a017210d3acca81f3373cbe5a3c102261f))
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # @kingsworld/plugin-cron
4
4
 
5
- **Plugin for <a href="https://github.com/sapphiredev/framework">@sapphire/framework</a> to add support for cron tasks using <a href="https://github.com/kelektiv/node-cron">cron</a>.**
5
+ **Plugin for <a href="https://github.com/sapphiredev/framework">@sapphire/framework</a> to add support for cron tasks using <a href="https://github.com/Hexagon/croner">croner</a>.**
6
6
 
7
7
  [![GitHub](https://img.shields.io/github/license/Kings-World/sapphire-plugins)](https://github.com/Kings-World/sapphire-plugins/blob/main/LICENSE.md)
8
8
  [![npm bundle size](https://pkg-size.dev/badge/bundle/83411)](https://pkg-size.dev/@kingsworld/plugin-cron)
@@ -16,14 +16,14 @@ This plugin adds support for cron tasks to the Sapphire framework. It uses the [
16
16
 
17
17
  ## Features
18
18
 
19
- - Full TypeScript support
20
- - Includes ESM entrypoint
19
+ - Full TypeScript support
20
+ - Includes ESM entrypoint
21
21
 
22
22
  ## Installation
23
23
 
24
24
  `@kingsworld/plugin-cron` depends on the following packages. Be sure to install these along with this package!
25
25
 
26
- - [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework)
26
+ - [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework)
27
27
 
28
28
  You can use the following command to install this package along with `cron`, or replace `npm install` with your package manager of choice.
29
29
 
@@ -46,7 +46,7 @@ Then, you can configure the plugin in the configuration options in your Sapphire
46
46
  ```ts
47
47
  const options = {
48
48
  ...otherClientOptionsGoHere,
49
- cron: {
49
+ cronTasks: {
50
50
  /**
51
51
  * Whether to disable Sentry cron monitoring
52
52
  * @default false
@@ -54,39 +54,47 @@ const options = {
54
54
  disableSentry: false,
55
55
  /**
56
56
  * The timezone to use for the cron tasks
57
- * @default 'system'
57
+ * @default undefined
58
58
  */
59
59
  defaultTimezone: 'Europe/London'
60
60
  }
61
61
  };
62
62
  ```
63
63
 
64
- - The `disableSentry` option is used to disable Sentry's cron monitoring. By default, it is set to `false`, which means Sentry cron monitoring is enabled if the `@sentry/node` package is installed and configured. This makes using Sentry an opt-in feature - you first opt in by installing `@sentry/node`. The `disableSentry` option then allows you to opt out in specific situations. You can set this to `true` to disable cron monitoring, which can be useful during development or if you haven't provided a Sentry DSN. If you don't use Sentry at all (i.e., `@sentry/node` is not installed), this option has no effect and can be safely ignored.
64
+ - The `disableSentry` option is used to disable Sentry's cron monitoring. By default, it is set to `false`, which means Sentry cron monitoring is enabled if the `@sentry/node` package is installed and configured. This makes using Sentry an opt-in feature - you first opt in by installing `@sentry/node`. The `disableSentry` option then allows you to opt out in specific situations. You can set this to `true` to disable cron monitoring, which can be useful during development or if you haven't provided a Sentry DSN. If you don't use Sentry at all (i.e., `@sentry/node` is not installed), this option has no effect and can be safely ignored.
65
65
 
66
- In order to use the cron tasks anywhere other than a piece (commands, arguments, preconditions, etc.), you must first import the `container` property of `@sapphire/framework`. For pieces, you can simply use `this.container.cron` to access this plugin's methods.
66
+ In order to use the cron tasks anywhere other than a piece (commands, arguments, preconditions, etc.), you must first import the `container` property of `@sapphire/framework`. From there, you can access the store.
67
67
 
68
- This is a simple example of how to start a task from a service.
68
+ This is a simple example of how to pause and resume a task from a service.
69
69
 
70
70
  ```typescript
71
71
  import { container } from '@sapphire/framework';
72
72
 
73
73
  export class MyAwesomeService {
74
74
  public createAwesomeTask() {
75
- const task = container.cron.store.get('my-awesome-task');
75
+ const task = container.stores.get('cron-tasks').get('my-awesome-task');
76
76
 
77
- task.job.start();
77
+ // To pause the task:
78
+ task.job.pause();
79
+
80
+ // To resume the task:
81
+ task.job.resume();
78
82
  }
79
83
  }
80
84
  ```
81
85
 
82
- This is a simple example of how to start all tasks from a service.
86
+ This is a simple example of how to pause or resume all tasks from a service.
83
87
 
84
88
  ```typescript
85
89
  import { container } from '@sapphire/framework';
86
90
 
87
91
  export class MyAwesomeService {
88
92
  public createAwesomeTask() {
89
- container.cron.startAll();
93
+ // To pause all tasks:
94
+ container.stores.get('cron-tasks').pauseAll();
95
+
96
+ // To resume all tasks:
97
+ container.stores.get('cron-tasks').resumeAll();
90
98
  }
91
99
  }
92
100
  ```
@@ -106,7 +114,7 @@ export class PingPong extends CronTask {
106
114
  public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
107
115
  super(context, {
108
116
  ...options,
109
- cronTime: '* * * * *'
117
+ pattern: '* * * * *'
110
118
  });
111
119
  }
112
120
 
@@ -129,7 +137,7 @@ export class PingPong extends CronTask {
129
137
  public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
130
138
  super(context, {
131
139
  ...options,
132
- cronTime: '* * * * *'
140
+ pattern: '* * * * *'
133
141
  });
134
142
  }
135
143
 
@@ -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 = "3.0.1-next.e1b3c15";
9
+ var version = "3.0.1";
10
10
 
11
11
  exports.version = version;
12
12
  Object.keys(CronTaskHandler_cjs).forEach(function (k) {
@@ -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 = '3.0.1-next.e1b3c15';\n"]}
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\tcronTasks: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcronTasks?: Partial<CronTaskHandlerOptions>;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '3.0.1';\n"]}
@@ -1,16 +1,14 @@
1
1
  import { Piece, Store } from '@sapphire/pieces';
2
2
  import { Awaitable } from '@sapphire/framework';
3
- import { CronJobParams, CronJob } from 'cron';
3
+ import { CronOptions, Cron } from 'croner';
4
4
  import Sentry from '@sentry/node';
5
5
 
6
6
  interface CronTaskHandlerOptions {
7
7
  /**
8
- * The default timezone to use for all cron tasks.
9
- * You can override this per task, using the timeZone option.
10
- * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
11
- * @default 'system'
8
+ * The default IANA timezone to use for all cron jobs.
9
+ * You can override this per task, using the timezone option.
12
10
  */
13
- defaultTimezone: string;
11
+ defaultTimezone?: string;
14
12
  /**
15
13
  * The ability to opt-out of instrumenting cron jobs with Sentry.
16
14
  * If you don't use Sentry, you can ignore this option.
@@ -19,7 +17,15 @@ interface CronTaskHandlerOptions {
19
17
  */
20
18
  disableSentry: boolean;
21
19
  }
22
- type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
20
+ interface CronJobOptions extends Pick<CronOptions, 'maxRuns' | 'unref' | 'timezone'> {
21
+ pattern: string | Date;
22
+ /**
23
+ * If true, prevents the job from running if the previous execution is still in progress.
24
+ * If the task has a protect method, it will be called if the job is blocked.
25
+ * @default false
26
+ */
27
+ protect?: boolean;
28
+ }
23
29
 
24
30
  /**
25
31
  * @example
@@ -32,7 +38,7 @@ type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete
32
38
  * public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
33
39
  * super(context, {
34
40
  * ...options,
35
- * cronTime: '* * * * *'
41
+ * pattern: '* * * * *'
36
42
  * });
37
43
  * }
38
44
  *
@@ -43,9 +49,11 @@ type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete
43
49
  * ```
44
50
  */
45
51
  declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
46
- job: CronJob<null, CronTask>;
52
+ job: Cron;
47
53
  constructor(context: CronTask.LoaderContext, options: Options);
48
54
  abstract run(): Awaitable<unknown>;
55
+ abstract protect?(job: Cron): Awaitable<unknown>;
56
+ abstract catch?(error: unknown, job: Cron): Awaitable<unknown>;
49
57
  /**
50
58
  * A helper function to log messages with the `CronTask[${name}]` prefix.
51
59
  * @param message The message to include after the prefix
@@ -97,33 +105,60 @@ declare namespace CronTask {
97
105
  declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
98
106
  constructor();
99
107
  /**
100
- * Loops over all tasks and starts those that are enabled.
101
- * This gets called automatically when the Client is ready.
108
+ * Loops over all tasks and pauses those that are running.
109
+ *
110
+ * @remarks
111
+ * This method will only pause tasks that:
112
+ * - Are enabled
113
+ * - Are currently running
114
+ * - Have not been permanently stopped
115
+ *
102
116
  * @returns CronTaskStore
103
117
  */
104
- startAll(): this;
118
+ pauseAll(): this;
119
+ /**
120
+ * Loops over all tasks and resumes those that are paused.
121
+ *
122
+ * @remarks
123
+ * This method will only resume tasks that:
124
+ * - Are enabled
125
+ * - Are not currently running
126
+ * - Have not been permanently stopped
127
+ *
128
+ * @returns CronTaskStore
129
+ */
130
+ resumeAll(): this;
105
131
  /**
106
132
  * Loops over all tasks and stops those that are running.
133
+ *
134
+ * @remarks
135
+ * This method will only stop tasks that:
136
+ * - Are enabled
137
+ * - Have not been permanently stopped
138
+ *
139
+ * ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!
140
+ *
107
141
  * @returns CronTaskStore
108
142
  */
109
143
  stopAll(): this;
110
144
  set(key: string, value: CronTask): this;
145
+ /**
146
+ * Deletes a task from the store and stops it if it's running.
147
+ */
111
148
  delete(key: string): boolean;
112
149
  /**
113
150
  * Stops all running cron jobs and clears the store.
114
- * @returns void
115
151
  */
116
152
  clear(): void;
117
153
  }
118
154
 
119
155
  declare class CronTaskHandler {
120
156
  /**
121
- * The default timezone to use for all cron tasks.
122
- * You can override this per task, using the timeZone option.
123
- * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
124
- * @default 'system'
157
+ * The default IANA/TZ timezone to use for all cron jobs.
158
+ * You can override this per task, using the timezone option.
159
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
125
160
  */
126
- defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];
161
+ defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];
127
162
  /**
128
163
  * The ability to opt-out of instrumenting cron jobs with Sentry.
129
164
  * If you don't use Sentry, you can ignore this option.
@@ -137,25 +172,12 @@ declare class CronTaskHandler {
137
172
  * is installed and the {@linkcode disableSentry} option is set to false.
138
173
  */
139
174
  sentry?: typeof Sentry;
140
- constructor(options?: CronTaskHandlerOptions);
141
- /**
142
- * Start all enabled cron jobs.
143
- * This gets called automatically when the Client is ready.
144
- */
145
- startAll(): void;
146
- /**
147
- * Stop all running cron jobs.
148
- */
149
- stopAll(): void;
150
- /**
151
- * Get the cron task store.
152
- */
153
- private get store();
175
+ constructor(options?: Partial<CronTaskHandlerOptions>);
154
176
  }
155
177
 
156
178
  declare module '@sapphire/pieces' {
157
179
  interface Container {
158
- cron: CronTaskHandler;
180
+ cronTasks: CronTaskHandler;
159
181
  }
160
182
  interface StoreRegistryEntries {
161
183
  'cron-tasks': CronTaskStore;
@@ -163,7 +185,7 @@ declare module '@sapphire/pieces' {
163
185
  }
164
186
  declare module 'discord.js' {
165
187
  interface ClientOptions {
166
- cron?: CronTaskHandlerOptions;
188
+ cronTasks?: Partial<CronTaskHandlerOptions>;
167
189
  }
168
190
  }
169
191
  /**
@@ -174,4 +196,5 @@ declare module 'discord.js' {
174
196
  */
175
197
  declare const version: string;
176
198
 
177
- export { type CronJobOptions, CronTask, CronTaskHandler, type CronTaskHandlerOptions, CronTaskStore, version };
199
+ export { CronTask, CronTaskHandler, CronTaskStore, version };
200
+ export type { CronJobOptions, CronTaskHandlerOptions };
@@ -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 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
- * @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 ?? "system";
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":["container"],"mappings":";;;;;;;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAwBrB,YAAY,OAAkC,EAAA;AAjBrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGN,IAAK,IAAA,CAAA,eAAA,GAAkB,SAAS,eAAmB,IAAA,QAAA,CAAA;AACnD,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,KAAA,CAAA;AAAA,GAChD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAW,GAAA;AACjB,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACrB;AAAA;AAAA;AAAA;AAAA,EAKO,OAAU,GAAA;AAChB,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACpB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAY,KAAQ,GAAA;AACnB,IAAO,OAAAA,mBAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GACzC;AACD,CAAA,CAAA;AAlD6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.cjs","sourcesContent":["import { container } from '@sapphire/framework';\nimport type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default timezone to use for all cron tasks.\n\t * You can override this per task, using the timeZone option.\n\t * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone\n\t * @default 'system'\n\t */\n\tpublic defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];\n\n\t/**\n\t * The ability to opt-out of instrumenting cron jobs with Sentry.\n\t * If you don't use Sentry, you can ignore this option.\n\t * @see https://docs.sentry.io/product/crons/\n\t * @default false\n\t */\n\tpublic disableSentry: boolean;\n\n\t/**\n\t * The Sentry instance to use for instrumenting cron jobs.\n\t * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)\n\t * is installed and the {@linkcode disableSentry} option is set to false.\n\t */\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: CronTaskHandlerOptions) {\n\t\tthis.defaultTimezone = options?.defaultTimezone ?? 'system';\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n\n\t/**\n\t * Start all enabled cron jobs.\n\t * This gets called automatically when the Client is ready.\n\t */\n\tpublic startAll() {\n\t\tthis.store.startAll();\n\t}\n\n\t/**\n\t * Stop all running cron jobs.\n\t */\n\tpublic stopAll() {\n\t\tthis.store.stopAll();\n\t}\n\n\t/**\n\t * Get the cron task store.\n\t */\n\tprivate get store() {\n\t\treturn container.stores.get('cron-tasks');\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;;;;;;AAGO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAuBrB,YAAY,OAA2C,EAAA;AAjB9D;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAS,EAAA,eAAA;AAChC,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,KAAA;AAAA;AAEjD,CAAA;AA3B6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.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,CAAA;AAAA,GACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AACD,CAAA,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.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\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tcronTime: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\tpublic declare job: CronJob<null, CronTask>;\n\n\tpublic constructor(context: CronTask.LoaderContext, options: Options) {\n\t\tsuper(context, options);\n\t}\n\n\tpublic abstract run(): Awaitable<unknown>;\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.info('Hello world!'); // CronTask[my-task] Hello world!\n\t */\n\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!\n\t */\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!\n\t */\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!\n\t */\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.\n\t */\n\tpublic trace(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n}\n\nexport namespace CronTask {\n\texport type Options = Piece.Options & CronJobOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'cron-tasks'>;\n}\n"]}
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,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;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;AAnEyH,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\tpattern: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\tdeclare public job: Cron;\n\n\tpublic constructor(context: CronTask.LoaderContext, options: Options) {\n\t\tsuper(context, options);\n\t}\n\n\tpublic abstract run(): Awaitable<unknown>;\n\n\tpublic abstract protect?(job: Cron): Awaitable<unknown>;\n\n\tpublic abstract catch?(error: unknown, job: Cron): Awaitable<unknown>;\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.info('Hello world!'); // CronTask[my-task] Hello world!\n\t */\n\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!\n\t */\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!\n\t */\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!\n\t */\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.\n\t */\n\tpublic trace(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n}\n\nexport namespace CronTask {\n\texport type Options = Piece.Options & CronJobOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'cron-tasks'>;\n}\n"]}