adonisjs-scheduler
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -5,2 +5,3 @@ import { BaseCommand } from '@adonisjs/core/build/standalone'; | ||
static description: string; | ||
static aliases: string[]; | ||
static settings: { | ||
@@ -7,0 +8,0 @@ loadApp: boolean; |
@@ -12,3 +12,3 @@ "use strict"; | ||
const Ace = this.application.container.use('Adonis/Core/Ace'); | ||
for (const command of Scheduler.commands) { | ||
for (const command of Scheduler.items) { | ||
node_cron_1.default.schedule(command.expression, async () => { | ||
@@ -41,2 +41,10 @@ switch (command.type) { | ||
}); | ||
Object.defineProperty(SchedulerCommand, "aliases", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: [ | ||
'scheduler:work' | ||
] | ||
}); | ||
Object.defineProperty(SchedulerCommand, "settings", { | ||
@@ -43,0 +51,0 @@ enumerable: true, |
declare abstract class BaseSchedule { | ||
abstract type: string; | ||
expression: string; | ||
everyMinutes(minutes: number): this; | ||
everyMinute(): this; | ||
everyTwoMinutes(): this; | ||
everyThreeMinutes(): this; | ||
everyFourMinutes(): this; | ||
everyFiveMinutes(): this; | ||
everyTenMinutes(): this; | ||
everyFifteenMinutes(): this; | ||
everyThirtyMinutes(): this; | ||
hourly(): this; | ||
everyHours(hours: number): this; | ||
everyTwoHours(): this; | ||
everyThreeHours(): this; | ||
everyFourHours(): this; | ||
everyFiveHours(): this; | ||
everySixHours(): this; | ||
daily(): this; | ||
weekly(): this; | ||
monthly(): this; | ||
quarterly(): this; | ||
yearly(): this; | ||
everySecond(): this; | ||
everySeconds(second: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59): this; | ||
everyFiveSeconds(): this; | ||
everyTenSeconds(): this; | ||
everyFifteenSeconds(): this; | ||
everyThirtySeconds(): this; | ||
cron(expression: string): this; | ||
@@ -20,7 +45,6 @@ } | ||
export declare class Scheduler { | ||
commands: BaseSchedule[]; | ||
items: BaseSchedule[]; | ||
command(name: string, args?: string[]): ScheduleCommand; | ||
callback(callback: Function): ScheduleCallback; | ||
closure(callback: Function): ScheduleCallback; | ||
call(callback: Function): ScheduleCallback; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Scheduler = void 0; | ||
const node_cron_expression_1 = require("node-cron-expression"); | ||
class BaseSchedule { | ||
@@ -13,10 +14,94 @@ constructor() { | ||
} | ||
everyMinutes(minutes) { | ||
this.expression = (0, node_cron_expression_1.every)(minutes).minutes().toString(); | ||
return this; | ||
} | ||
everyMinute() { | ||
this.expression = "* * * * *"; | ||
this.expression = (0, node_cron_expression_1.everyMinute)().toString(); | ||
return this; | ||
} | ||
everyFiveSeconds() { | ||
this.expression = "*/5 * * * * *"; | ||
everyTwoMinutes() { | ||
return this.everyMinutes(2); | ||
} | ||
everyThreeMinutes() { | ||
return this.everyMinutes(3); | ||
} | ||
everyFourMinutes() { | ||
return this.everyMinutes(4); | ||
} | ||
everyFiveMinutes() { | ||
return this.everyMinutes(5); | ||
} | ||
everyTenMinutes() { | ||
return this.everyMinutes(10); | ||
} | ||
everyFifteenMinutes() { | ||
return this.everyMinutes(15); | ||
} | ||
everyThirtyMinutes() { | ||
return this.everyMinutes(30); | ||
} | ||
hourly() { | ||
this.expression = (0, node_cron_expression_1.everyHour)().toString(); | ||
return this; | ||
} | ||
everyHours(hours) { | ||
this.expression = (0, node_cron_expression_1.every)(hours).hours().toString(); | ||
return this; | ||
} | ||
everyTwoHours() { | ||
return this.everyHours(2); | ||
} | ||
everyThreeHours() { | ||
return this.everyHours(3); | ||
} | ||
everyFourHours() { | ||
return this.everyHours(5); | ||
} | ||
everyFiveHours() { | ||
return this.everyHours(6); | ||
} | ||
everySixHours() { | ||
return this.everyHours(6); | ||
} | ||
daily() { | ||
this.expression = '0 0 * * *'; | ||
return this; | ||
} | ||
weekly() { | ||
this.expression = '0 0 * * 0'; | ||
return this; | ||
} | ||
monthly() { | ||
this.expression = '0 0 1 * *'; | ||
return this; | ||
} | ||
quarterly() { | ||
this.expression = '0 0 1 */3 *'; | ||
return this; | ||
} | ||
yearly() { | ||
this.expression = '0 0 1 1 *'; | ||
return this; | ||
} | ||
everySecond() { | ||
this.expression = "* * * * * *"; | ||
return this; | ||
} | ||
everySeconds(second) { | ||
this.expression = `*/${second} * * * * *`; | ||
return this; | ||
} | ||
everyFiveSeconds() { | ||
return this.everySeconds(5); | ||
} | ||
everyTenSeconds() { | ||
return this.everySeconds(10); | ||
} | ||
everyFifteenSeconds() { | ||
return this.everySeconds(15); | ||
} | ||
everyThirtySeconds() { | ||
return this.everySeconds(30); | ||
} | ||
cron(expression) { | ||
@@ -72,3 +157,3 @@ this.expression = expression; | ||
constructor() { | ||
Object.defineProperty(this, "commands", { | ||
Object.defineProperty(this, "items", { | ||
enumerable: true, | ||
@@ -82,14 +167,11 @@ configurable: true, | ||
let newCommand = new ScheduleCommand(name, args); | ||
this.commands.push(newCommand); | ||
this.items.push(newCommand); | ||
return newCommand; | ||
} | ||
callback(callback) { | ||
call(callback) { | ||
let newCommand = new ScheduleCallback(callback); | ||
this.commands.push(newCommand); | ||
this.items.push(newCommand); | ||
return newCommand; | ||
} | ||
closure(callback) { | ||
return this.callback(callback); | ||
} | ||
} | ||
exports.Scheduler = Scheduler; |
@@ -5,4 +5,4 @@ import Scheduler from "@ioc:Adonis/Addons/Scheduler" | ||
Scheduler.callback(() => { | ||
console.log("Hello !"); | ||
}).everyFiveSeconds(); | ||
Scheduler.call(() => { | ||
console.log("Pruge DB!"); | ||
}).weekly(); |
{ | ||
"name": "adonisjs-scheduler", | ||
"version": "0.0.7", | ||
"description": "", | ||
"version": "0.0.8", | ||
"description": "Task scheduler for AdonisJS", | ||
"homepage": "https://github.com/KABBOUCHI/adonisjs-scheduler#readme", | ||
@@ -81,4 +81,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"node-cron": "^3.0.2" | ||
"node-cron": "^3.0.2", | ||
"node-cron-expression": "^1.3.0" | ||
} | ||
} |
@@ -15,2 +15,49 @@ # adonisjs-scheduler | ||
node ace configure adonisjs-scheduler | ||
``` | ||
``` | ||
## Running The Scheduler | ||
```sh | ||
node ace scheduler:run | ||
# or | ||
node ace scheduler:work | ||
``` | ||
## Defining Schedules | ||
```ts | ||
// start/scheduler.ts | ||
import Scheduler from "@ioc:Adonis/Addons/Scheduler" | ||
Scheduler.command("inspire").everyFiveSeconds(); | ||
Scheduler.call(() => { | ||
console.log("Pruge DB!"); | ||
}).weekly(); | ||
``` | ||
## Schedule Frequency Options | ||
Method | Description | ||
------------- | ------------- | ||
`.cron('* * * * *');` | Run the task on a custom cron schedule | ||
`.everyMinute();` | Run the task every minute | ||
`.everyTwoMinutes();` | Run the task every two minutes | ||
`.everyThreeMinutes();` | Run the task every three minutes | ||
`.everyFourMinutes();` | Run the task every four minutes | ||
`.everyFiveMinutes();` | Run the task every five minutes | ||
`.everyTenMinutes();` | Run the task every ten minutes | ||
`.everyFifteenMinutes();` | Run the task every fifteen minutes | ||
`.everyThirtyMinutes();` | Run the task every thirty minutes | ||
`.hourly();` | Run the task every hour | ||
`.everyTwoHours();` | Run the task every two hours | ||
`.everyThreeHours();` | Run the task every three hours | ||
`.everyFourHours();` | Run the task every four hours | ||
`.everyFiveHours();` | Run the task every five hours | ||
`.everySixHours();` | Run the task every six hours | ||
`.daily();` | Run the task every day at midnight | ||
`.weekly();` | Run the task every Sunday at 00:00 | ||
`.monthly();` | Run the task on the first day of every month at 00:00 | ||
`.quarterly();` | Run the task on the first day of every quarter at 00:00 | ||
`.yearly();` | Run the task on the first day of every year at 00:00 | ||
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
19319
419
63
2
+ Addednode-cron-expression@^1.3.0
+ Addednode-cron-expression@1.3.1(transitive)