@sapphire/plugin-scheduled-tasks 1.0.0 → 1.1.0
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 +15 -4
- package/dist/lib/ScheduledTaskHandler.d.ts +1 -2
- package/dist/lib/ScheduledTaskHandler.d.ts.map +1 -1
- package/dist/lib/ScheduledTaskHandler.js +16 -2
- package/dist/lib/ScheduledTaskHandler.js.map +1 -1
- package/dist/lib/strategies/ScheduledTaskRedisStrategy.d.ts +1 -1
- package/dist/lib/strategies/ScheduledTaskSQSStrategy.d.ts +1 -1
- package/dist/lib/types/ScheduledTaskEvents.d.ts +8 -0
- package/dist/lib/types/ScheduledTaskEvents.d.ts.map +1 -0
- package/dist/lib/types/ScheduledTaskEvents.js +12 -0
- package/dist/lib/types/ScheduledTaskEvents.js.map +1 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ In case you want to use sqs as your provider:
|
|
|
37
37
|
- [`sqs-consumer`](https://www.npmjs.com/package/sqs-consumer)
|
|
38
38
|
- [`sqs-producer`](https://www.npmjs.com/package/sqs-producer)
|
|
39
39
|
|
|
40
|
-
You can use the following command to install this package with bull, or replace `npm install` with your package manager of choice.
|
|
40
|
+
You can use the following command to install this package along with bull, or replace `npm install` with your package manager of choice.
|
|
41
41
|
|
|
42
42
|
```sh
|
|
43
43
|
npm install @sapphire/plugin-scheduled-tasks @sapphire/framework bull
|
|
@@ -64,10 +64,21 @@ Then, you can pass the imported Strategy into the configuration options in your
|
|
|
64
64
|
const options = {
|
|
65
65
|
...otherClientOptionsGoHere,
|
|
66
66
|
tasks: {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
// Using bull (redis)
|
|
68
|
+
strategy: new ScheduledTaskRedisStrategy({
|
|
69
|
+
/* You can add your Bull options here, for example we can configure custom Redis connection options: */
|
|
70
|
+
bull: {
|
|
71
|
+
redis: {
|
|
72
|
+
port: 8888, // Defaults to 6379, but if your Redis server runs on another port configure it here
|
|
73
|
+
password: 'very-strong-password', // If your Redis server requires a password configure it here
|
|
74
|
+
host: 'localhost', // The host at which the redis server is found
|
|
75
|
+
db: 2 // Redis database number, defaults to 0 but can be any value between 0 and 15
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}),
|
|
79
|
+
// Or with SQS
|
|
69
80
|
strategy: new ScheduledTaskSQSStrategy({
|
|
70
|
-
/*
|
|
81
|
+
/* You can add your SQS options here */
|
|
71
82
|
})
|
|
72
83
|
}
|
|
73
84
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Awaitable } from '@sapphire/utilities';
|
|
2
1
|
import type { ScheduledTaskBaseStrategy, ScheduledTasksOptions, ScheduledTasksTaskOptions } from './types';
|
|
3
2
|
export declare class ScheduledTaskHandler {
|
|
4
3
|
readonly strategy: ScheduledTaskBaseStrategy;
|
|
@@ -6,7 +5,7 @@ export declare class ScheduledTaskHandler {
|
|
|
6
5
|
connect(): Promise<void>;
|
|
7
6
|
create(task: string, payload: unknown, options?: ScheduledTasksTaskOptions | number): void;
|
|
8
7
|
createRepeated(): void;
|
|
9
|
-
run(task: string, payload: unknown):
|
|
8
|
+
run(task: string, payload: unknown): Promise<unknown>;
|
|
10
9
|
private get store();
|
|
11
10
|
}
|
|
12
11
|
//# sourceMappingURL=ScheduledTaskHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScheduledTaskHandler.d.ts","sourceRoot":"","sources":["../../src/lib/ScheduledTaskHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ScheduledTaskHandler.d.ts","sourceRoot":"","sources":["../../src/lib/ScheduledTaskHandler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAG3G,qBAAa,oBAAoB;IAChC,SAAgB,QAAQ,EAAE,yBAAyB,CAAC;gBAEjC,OAAO,EAAE,qBAAqB,GAAG,SAAS;IAIhD,OAAO;IAIb,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,MAAM;IAWnF,cAAc;IAkBR,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAuBlE,OAAO,KAAK,KAAK,GAEhB;CACD"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ScheduledTaskHandler = void 0;
|
|
4
4
|
const framework_1 = require("@sapphire/framework");
|
|
5
5
|
const ScheduledTaskRedisStrategy_1 = require("./strategies/ScheduledTaskRedisStrategy");
|
|
6
|
+
const ScheduledTaskEvents_1 = require("./types/ScheduledTaskEvents");
|
|
6
7
|
class ScheduledTaskHandler {
|
|
7
8
|
constructor(options) {
|
|
8
9
|
Object.defineProperty(this, "strategy", {
|
|
@@ -39,9 +40,22 @@ class ScheduledTaskHandler {
|
|
|
39
40
|
}
|
|
40
41
|
})));
|
|
41
42
|
}
|
|
42
|
-
run(task, payload) {
|
|
43
|
+
async run(task, payload) {
|
|
43
44
|
const piece = this.store.get(task);
|
|
44
|
-
|
|
45
|
+
if (!piece) {
|
|
46
|
+
framework_1.container.client.emit(ScheduledTaskEvents_1.ScheduledTaskEvents.ScheduledTaskNotFound, task, payload);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const result = await (0, framework_1.fromAsync)(async () => {
|
|
50
|
+
framework_1.container.client.emit(ScheduledTaskEvents_1.ScheduledTaskEvents.ScheduledTaskRun, task, payload);
|
|
51
|
+
const result = await piece.run(payload);
|
|
52
|
+
framework_1.container.client.emit(ScheduledTaskEvents_1.ScheduledTaskEvents.ScheduledTaskSuccess, task, payload, result);
|
|
53
|
+
});
|
|
54
|
+
if ((0, framework_1.isErr)(result)) {
|
|
55
|
+
framework_1.container.client.emit(ScheduledTaskEvents_1.ScheduledTaskEvents.ScheduledTaskError, result.error, task, payload);
|
|
56
|
+
}
|
|
57
|
+
framework_1.container.client.emit(ScheduledTaskEvents_1.ScheduledTaskEvents.ScheduledTaskFinished, task, payload);
|
|
58
|
+
return result;
|
|
45
59
|
}
|
|
46
60
|
get store() {
|
|
47
61
|
return framework_1.container.client.stores.get('scheduled-tasks');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScheduledTaskHandler.js","sourceRoot":"","sources":["../../src/lib/ScheduledTaskHandler.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ScheduledTaskHandler.js","sourceRoot":"","sources":["../../src/lib/ScheduledTaskHandler.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAClE,wFAAqF;AAGrF,qEAAkE;AAElE,MAAa,oBAAoB;IAGhC,YAAmB,OAA0C;QAF7D;;;;;WAAoD;QAGnD,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,IAAI,uDAA0B,EAAE,CAAC;IACvE,CAAC;IAEM,KAAK,CAAC,OAAO;QACnB,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,IAAY,EAAE,OAAgB,EAAE,OAA4C;QACzF,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAChC,OAAO,GAAG;gBACT,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,OAAO;aACd,CAAC;SACF;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAEM,cAAc;QACpB,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAClC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;Y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;QAEhF,OAAO,MAAM,CAAC;IACf,CAAC;IAED,IAAY,KAAK;QAChB,OAAO,qBAAS,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACvD,CAAC;CACD;AAlED,oDAkEC"}
|
|
@@ -17,6 +17,6 @@ export declare class ScheduledTaskRedisStrategy implements ScheduledTaskBaseStra
|
|
|
17
17
|
connect(): Promise<void>;
|
|
18
18
|
create(task: string, payload?: unknown, options?: ScheduledTasksTaskOptions): Promise<Bull.Job<any>> | undefined;
|
|
19
19
|
createRepeated(tasks: ScheduledTaskCreateRepeatedTask[]): Promise<void>;
|
|
20
|
-
run(task: string, payload: unknown): unknown
|
|
20
|
+
run(task: string, payload: unknown): Promise<unknown>;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=ScheduledTaskRedisStrategy.d.ts.map
|
|
@@ -13,7 +13,7 @@ export declare class ScheduledTaskSQSStrategy implements ScheduledTaskBaseStrate
|
|
|
13
13
|
connect(): void;
|
|
14
14
|
create(task: string, payload?: unknown, options?: ScheduledTasksTaskOptions): Promise<import("aws-sdk/clients/sqs").SendMessageBatchResultEntryList>;
|
|
15
15
|
createRepeated(tasks: ScheduledTaskCreateRepeatedTask[]): Promise<void>;
|
|
16
|
-
run(task: string, payload: unknown): unknown
|
|
16
|
+
run(task: string, payload: unknown): Promise<unknown>;
|
|
17
17
|
private handleMessage;
|
|
18
18
|
private handleBatch;
|
|
19
19
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare enum ScheduledTaskEvents {
|
|
2
|
+
ScheduledTaskNotFound = "scheduledTaskNotFound",
|
|
3
|
+
ScheduledTaskRun = "scheduledTaskRun",
|
|
4
|
+
ScheduledTaskError = "scheduledTaskError",
|
|
5
|
+
ScheduledTaskSuccess = "scheduledTaskSuccess",
|
|
6
|
+
ScheduledTaskFinished = "scheduledTaskFinished"
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=ScheduledTaskEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScheduledTaskEvents.d.ts","sourceRoot":"","sources":["../../../src/lib/types/ScheduledTaskEvents.ts"],"names":[],"mappings":"AAAA,oBAAY,mBAAmB;IAC9B,qBAAqB,0BAA0B;IAC/C,gBAAgB,qBAAqB;IACrC,kBAAkB,uBAAuB;IACzC,oBAAoB,yBAAyB;IAC7C,qBAAqB,0BAA0B;CAC/C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScheduledTaskEvents = void 0;
|
|
4
|
+
var ScheduledTaskEvents;
|
|
5
|
+
(function (ScheduledTaskEvents) {
|
|
6
|
+
ScheduledTaskEvents["ScheduledTaskNotFound"] = "scheduledTaskNotFound";
|
|
7
|
+
ScheduledTaskEvents["ScheduledTaskRun"] = "scheduledTaskRun";
|
|
8
|
+
ScheduledTaskEvents["ScheduledTaskError"] = "scheduledTaskError";
|
|
9
|
+
ScheduledTaskEvents["ScheduledTaskSuccess"] = "scheduledTaskSuccess";
|
|
10
|
+
ScheduledTaskEvents["ScheduledTaskFinished"] = "scheduledTaskFinished";
|
|
11
|
+
})(ScheduledTaskEvents = exports.ScheduledTaskEvents || (exports.ScheduledTaskEvents = {}));
|
|
12
|
+
//# sourceMappingURL=ScheduledTaskEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScheduledTaskEvents.js","sourceRoot":"","sources":["../../../src/lib/types/ScheduledTaskEvents.ts"],"names":[],"mappings":";;;AAAA,IAAY,mBAMX;AAND,WAAY,mBAAmB;IAC9B,sEAA+C,CAAA;IAC/C,4DAAqC,CAAA;IACrC,gEAAyC,CAAA;IACzC,oEAA6C,CAAA;IAC7C,sEAA+C,CAAA;AAChD,CAAC,EANW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAM9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-scheduled-tasks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Plugin for @sapphire/framework to have scheduled tasks",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"prepublishOnly": "yarn build"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@sapphire/time-utilities": "^1.
|
|
44
|
+
"@sapphire/time-utilities": "^1.5.0",
|
|
45
45
|
"tslib": "^2.3.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@types/bull": "^3.15.
|
|
49
|
-
"bull": "^
|
|
48
|
+
"@types/bull": "^3.15.7",
|
|
49
|
+
"bull": "^4.2.0",
|
|
50
50
|
"sqs-consumer": "^5.6.0",
|
|
51
51
|
"sqs-producer": "^2.1.0"
|
|
52
52
|
},
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"publishConfig": {
|
|
82
82
|
"access": "public"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "759d7a652a6fd9c000e9ea7d3a1382beb042cd1e"
|
|
85
85
|
}
|