adonisjs-scheduler
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -14,3 +14,11 @@ "use strict"; | ||
node_cron_1.default.schedule(command.expression, async () => { | ||
await Ace.exec(command.commandName, command.commandArgs); | ||
switch (command.type) { | ||
case "command": | ||
await Ace.exec(command.commandName, command.commandArgs); | ||
break; | ||
case "callback": | ||
await command.callback(); | ||
default: | ||
break; | ||
} | ||
}); | ||
@@ -17,0 +25,0 @@ } |
@@ -1,6 +0,4 @@ | ||
declare class ScheduleCommand { | ||
commandName: string; | ||
commandArgs: string[]; | ||
declare abstract class BaseSchedule { | ||
abstract type: string; | ||
expression: string; | ||
constructor(commandName: string, commandArgs?: string[]); | ||
everyMinute(): this; | ||
@@ -10,6 +8,19 @@ everyFiveSeconds(): this; | ||
} | ||
declare class ScheduleCommand extends BaseSchedule { | ||
type: string; | ||
commandName: string; | ||
commandArgs: string[]; | ||
constructor(commandName: string, commandArgs?: string[]); | ||
} | ||
declare class ScheduleCallback extends BaseSchedule { | ||
type: string; | ||
callback: Function; | ||
constructor(callback: Function); | ||
} | ||
export declare class Scheduler { | ||
commands: ScheduleCommand[]; | ||
commands: BaseSchedule[]; | ||
command(name: string, args?: string[]): ScheduleCommand; | ||
callback(callback: Function): ScheduleCallback; | ||
closure(callback: Function): ScheduleCallback; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Scheduler = void 0; | ||
class ScheduleCommand { | ||
constructor(commandName, commandArgs = []) { | ||
Object.defineProperty(this, "commandName", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "commandArgs", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
class BaseSchedule { | ||
constructor() { | ||
Object.defineProperty(this, "expression", { | ||
@@ -24,4 +12,2 @@ enumerable: true, | ||
}); | ||
this.commandName = commandName; | ||
this.commandArgs = commandArgs; | ||
} | ||
@@ -41,2 +27,45 @@ everyMinute() { | ||
} | ||
class ScheduleCommand extends BaseSchedule { | ||
constructor(commandName, commandArgs = []) { | ||
super(); | ||
Object.defineProperty(this, "type", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: "command" | ||
}); | ||
Object.defineProperty(this, "commandName", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "commandArgs", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
this.commandName = commandName; | ||
this.commandArgs = commandArgs; | ||
} | ||
} | ||
class ScheduleCallback extends BaseSchedule { | ||
constructor(callback) { | ||
super(); | ||
Object.defineProperty(this, "type", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: "callback" | ||
}); | ||
Object.defineProperty(this, "callback", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
this.callback = callback; | ||
} | ||
} | ||
class Scheduler { | ||
@@ -56,3 +85,11 @@ constructor() { | ||
} | ||
callback(callback) { | ||
let newCommand = new ScheduleCallback(callback); | ||
this.commands.push(newCommand); | ||
return newCommand; | ||
} | ||
closure(callback) { | ||
return this.callback(callback); | ||
} | ||
} | ||
exports.Scheduler = Scheduler; |
import Scheduler from "@ioc:Adonis/Addons/Scheduler" | ||
Scheduler.command("inspire").everyFiveSeconds(); | ||
Scheduler.command("inspire").everyFiveSeconds(); | ||
Scheduler.callback(() => { | ||
console.log("Hello !"); | ||
}).everyFiveSeconds(); |
{ | ||
"name": "adonisjs-scheduler", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/KABBOUCHI/adonisjs-scheduler#readme", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14556
304