This commit is contained in:
Evert Prants 2021-10-01 21:44:48 +03:00
parent 2483a67088
commit 5ad6352a83
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 7 additions and 10 deletions

View File

@ -3,7 +3,7 @@
"name": "cron", "name": "cron",
"description": "API for plugin-scoped cron tasks", "description": "API for plugin-scoped cron tasks",
"tags": ["timers", "cron", "scheduler", "api"], "tags": ["timers", "cron", "scheduler", "api"],
"version": "1.0.0", "version": "1.0.1",
"dependencies": ["control?"], "dependencies": ["control?"],
"npmDependencies": ["node-cron@3.0.0"] "npmDependencies": ["node-cron@2.0.3"]
} }

View File

@ -1,7 +1,6 @@
import { logger } from '@squeebot/core/lib/core'; import { logger } from '@squeebot/core/lib/core';
import { import {
Plugin, Plugin,
Configurable,
EventListener, EventListener,
IPlugin, IPlugin,
} from '@squeebot/core/lib/plugin'; } from '@squeebot/core/lib/plugin';
@ -36,7 +35,9 @@ class CronWrapper {
if (!this.cronTask) { if (!this.cronTask) {
this.assert(); this.assert();
this.cronTask = nodeCron.schedule(this.expression, this.execute, { this.cronTask = nodeCron.schedule(this.expression, () => {
this.taskFn.call(this.origin);
}, {
scheduled: false, scheduled: false,
}); });
} }
@ -65,10 +66,6 @@ class CronWrapper {
this.cronTask = null; this.cronTask = null;
} }
execute(): void {
this.taskFn.call(this.origin);
}
belongsTo(plugin: IPlugin | string): boolean { belongsTo(plugin: IPlugin | string): boolean {
if (typeof plugin === 'string') { if (typeof plugin === 'string') {
return this.origin.manifest.name === plugin; return this.origin.manifest.name === plugin;
@ -78,7 +75,6 @@ class CronWrapper {
} }
} }
// @Configurable({})
class CronPlugin extends Plugin { class CronPlugin extends Plugin {
private timers: CronWrapper[] = []; private timers: CronWrapper[] = [];
@ -134,6 +130,7 @@ class CronPlugin extends Plugin {
newTimer.start(); newTimer.start();
} }
this.timers.push(newTimer);
return newTimer; return newTimer;
} }

View File

@ -7,7 +7,7 @@
}, },
{ {
"name": "cron", "name": "cron",
"version": "1.0.0" "version": "1.0.1"
}, },
{ {
"name": "permissions", "name": "permissions",