@codenameryuu/adonis-scheduler 1.0.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ # The MIT License
2
+
3
+ Copyright (c) 2024 Codename Ryuu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # @codenameryuu/adonis-lucid-filter
2
+
3
+ This addon adds the functionality to schedule tasks in Adonis JS 7.
4
+
5
+ ## Requirement
6
+
7
+ * Adonis Js 7
8
+ * Lucid 22 or higher
9
+
10
+ ## Installation
11
+
12
+ Install the package from npm using the following command:
13
+
14
+ ```bash
15
+ node ace add @codenameryuu/adonis-scheduler
16
+ ```
17
+
18
+ ## Running The Scheduler
19
+
20
+ ```sh
21
+ node ace scheduler:run
22
+ # or
23
+ node ace scheduler:work
24
+
25
+ # automatically restart the scheduler when files are modified during development mode
26
+ node ace scheduler:run --watch
27
+
28
+ node ace scheduler:run --tag <tag_name> # Run all schedules with the specified tag
29
+ ```
30
+
31
+ ## Defining Schedules
32
+
33
+ ```ts
34
+ // start/scheduler.ts
35
+
36
+ import scheduler from '@codenameryuu/adonis-scheduler/services/main'
37
+
38
+ import PurgeUsers from '../commands/purge_users'
39
+
40
+ scheduler.command('inspire').everyFiveSeconds()
41
+ scheduler.command(PurgeUsers, ['30 days']).everyFiveSeconds().withoutOverlapping()
42
+
43
+ scheduler.withoutOverlapping(
44
+ () => {
45
+ scheduler.command('inspire').everySecond()
46
+ scheduler.command(PurgeUsers, ['30 days']).everyFiveSeconds()
47
+ },
48
+ { expiresAt: 30_000 }
49
+ )
50
+
51
+ scheduler.withTag(
52
+ () => {
53
+ scheduler.command('inspire').everySecond()
54
+ },
55
+ 'my-tag'
56
+ )
57
+
58
+ scheduler
59
+ .call(() => {
60
+ console.log('Pruge DB!')
61
+ })
62
+ .weekly()
63
+
64
+ scheduler
65
+ .call(() => {
66
+ console.log('Pruge DB!')
67
+ })
68
+ .tag('my-tag')
69
+ .weekly()
70
+ ```
71
+
72
+ or define schedule directly on command
73
+
74
+ ```ts
75
+ import { BaseCommand, args } from '@adonisjs/core/ace'
76
+ import { schedule } from '@codenameryuu/adonis-scheduler'
77
+
78
+ @schedule("* * * * *", ["30 days"])
79
+ @schedule((s) => s.everyFiveSeconds().immediate(), ["7 days"])
80
+ @schedule((s) => s.everyMinute(), ["42 days"])
81
+ export default class PurgeUsers extends BaseCommand {
82
+ static commandName = 'purge:users'
83
+ static description = ''
84
+
85
+ static options: CommandOptions = {}
86
+
87
+ @args.string()
88
+ declare olderThan: string
89
+
90
+ async run() {
91
+ //
92
+ }
93
+ }
94
+ ```
95
+
96
+ ## Schedule Frequency Options
97
+
98
+ | Method | Description |
99
+ | -------------------------------- | ------------------------------------------------------- |
100
+ | `.cron('* * * * *');` | Run the task on a custom cron schedule |
101
+ | `.everyMinute();` | Run the task every minute |
102
+ | `.everyTwoMinutes();` | Run the task every two minutes |
103
+ | `.everyThreeMinutes();` | Run the task every three minutes |
104
+ | `.everyFourMinutes();` | Run the task every four minutes |
105
+ | `.everyFiveMinutes();` | Run the task every five minutes |
106
+ | `.everyTenMinutes();` | Run the task every ten minutes |
107
+ | `.everyFifteenMinutes();` | Run the task every fifteen minutes |
108
+ | `.everyThirtyMinutes();` | Run the task every thirty minutes |
109
+ | `.hourly();` | Run the task every hour |
110
+ | `.hourlyAt(17);` | Run the task every hour at 17 minutes past the hour. |
111
+ | `.everyTwoHours();` | Run the task every two hours |
112
+ | `.everyThreeHours();` | Run the task every three hours |
113
+ | `.everyFourHours();` | Run the task every four hours |
114
+ | `.everyFiveHours();` | Run the task every five hours |
115
+ | `.everySixHours();` | Run the task every six hours |
116
+ | `.daily();` | Run the task every day at midnight |
117
+ | `.dailyAt('13:00');` | Run the task every day at 13:00. |
118
+ | `.twiceDaily(1, 13);` | Run the task daily at 1:00 & 13:00. |
119
+ | `.twiceDailyAt(1, 13, 15);` | Run the task daily at 1:15 & 13:15. |
120
+ | `.weekly();` | Run the task every Sunday at 00:00 |
121
+ | `.weeklyOn(1, '8:00');` | Run the task every week on Monday at 8:00. |
122
+ | `.monthly();` | Run the task on the first day of every month at 00:00 |
123
+ | `.monthlyOn(4, '15:00');` | Run the task every month on the 4th at 15:00. |
124
+ | `.twiceMonthly(1, 16, '13:00');` | Run the task monthly on the 1st and 16th at 13:00. |
125
+ | `.lastDayOfMonth('15:00');` | Run the task on the last day of the month at 15:00. |
126
+ | `.quarterly();` | Run the task on the first day of every quarter at 00:00.|
127
+ | `.quarterlyOn(4, '14:00');` | Run the task every quarter on the 4th at 14:00. |
128
+ | `.yearly();` | Run the task on the first day of every year at 00:00. |
129
+ | `.yearlyOn(6, 1, '17:00');` | Run the task every year on June 1st at 17:00. |
130
+ | `.timezone('America/New_York');` | Set the timezone for the task. |
131
+ | `.immediate();` | Run the task on startup |
132
+ | `.withoutOverlapping();` | Run the task without overlapping |
133
+
134
+ ## Alternative Ways to Run the Scheduler
135
+
136
+ Besides using `node ace scheduler:run` , you can also manually initialize and control the scheduler worker in your code:
137
+
138
+ ```ts
139
+ import { Worker } from '@codenameryuu/adonis-scheduler'
140
+ import app from '@adonisjs/core/services/app'
141
+
142
+ const worker = new Worker(app)
143
+
144
+ app.terminating(async () => {
145
+ await worker.stop()
146
+ })
147
+
148
+ await worker.start()
149
+ ```
150
+
151
+ Note: make sure to modify `adonisrc.ts` and include the environment where the worker is running.
152
+
153
+ ```ts
154
+ import { defineConfig } from '@adonisjs/core/app'
155
+
156
+ export default defineConfig({
157
+ providers: [
158
+ {
159
+ file: () => import('@codenameryuu/adonis-scheduler/scheduler_provider'),
160
+ environment: ['console', 'web'], // <---
161
+ },
162
+
163
+ // or enable for all environments
164
+ () => import('@codenameryuu/adonis-scheduler/scheduler_provider'),
165
+ })
166
+ ```
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { assert } from "@japa/assert";
2
+ import { configure, processCLIArgs, run } from "@japa/runner";
3
+ processCLIArgs(process.argv.slice(2));
4
+ configure({
5
+ files: ["tests/**/*.spec.ts"],
6
+ plugins: [assert()],
7
+ });
8
+ run();
@@ -0,0 +1 @@
1
+ {"commands":[{"commandName":"inspire","description":"","help":"","namespace":null,"aliases":[],"flags":[],"args":[],"options":{"startApp":true},"filePath":"inspire_command.js"},{"commandName":"scheduler:run","description":"","help":"","namespace":"scheduler","aliases":["scheduler:work","schedule:work","schedule:run"],"flags":[{"name":"watch","flagName":"watch","required":false,"type":"boolean","description":"Restart the scheduler on file changes"},{"name":"tag","flagName":"tag","required":false,"type":"string","description":"Tag for the scheduler","default":"default"}],"args":[],"options":{"startApp":true,"staysAlive":true},"filePath":"scheduler_command.js"},{"commandName":"scheduler:list","description":"","help":"","namespace":"scheduler","aliases":[],"flags":[{"name":"tag","flagName":"tag","required":false,"type":"string","description":"Filter by tag"}],"args":[],"options":{"startApp":true},"filePath":"scheduler_list_command.js"}],"version":1}
@@ -0,0 +1,8 @@
1
+ import { BaseCommand } from "@adonisjs/core/ace";
2
+ import { CommandOptions } from "@adonisjs/core/types/ace";
3
+ export default class InspireCommand extends BaseCommand {
4
+ static commandName: string;
5
+ static description: string;
6
+ static options: CommandOptions;
7
+ run(): Promise<void>;
8
+ }
@@ -0,0 +1,52 @@
1
+ import { BaseCommand } from "@adonisjs/core/ace";
2
+ const quotes = [
3
+ "Act only according to that maxim whereby you can, at the same time, will that it should become a universal law. - Immanuel Kant",
4
+ "An unexamined life is not worth living. - Socrates",
5
+ "Be present above all else. - Naval Ravikant",
6
+ "Do what you can, with what you have, where you are. - Theodore Roosevelt",
7
+ "Happiness is not something readymade. It comes from your own actions. - Dalai Lama",
8
+ "He who is contented is rich. - Laozi",
9
+ "I begin to speak only when I am certain what I will say is not better left unsaid. - Cato the Younger",
10
+ "I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison",
11
+ "If you do not have a consistent goal in life, you can not live it in a consistent way. - Marcus Aurelius",
12
+ "It is never too late to be what you might have been. - George Eliot",
13
+ "It is not the man who has too little, but the man who craves more, that is poor. - Seneca",
14
+ "It is quality rather than quantity that matters. - Lucius Annaeus Seneca",
15
+ "Knowing is not enough; we must apply. Being willing is not enough; we must do. - Leonardo da Vinci",
16
+ "Let all your things have their places; let each part of your business have its time. - Benjamin Franklin",
17
+ "Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi",
18
+ "No surplus words or unnecessary actions. - Marcus Aurelius",
19
+ "Nothing worth having comes easy. - Theodore Roosevelt",
20
+ "Order your soul. Reduce your wants. - Augustine",
21
+ "People find pleasure in different ways. I find it in keeping my mind clear. - Marcus Aurelius",
22
+ "Simplicity is an acquired taste. - Katharine Gerould",
23
+ "Simplicity is the consequence of refined emotions. - Jean D'Alembert",
24
+ "Simplicity is the essence of happiness. - Cedric Bledsoe",
25
+ "Simplicity is the ultimate sophistication. - Leonardo da Vinci",
26
+ "Smile, breathe, and go slowly. - Thich Nhat Hanh",
27
+ "The only way to do great work is to love what you do. - Steve Jobs",
28
+ "The whole future lies in uncertainty: live immediately. - Seneca",
29
+ "Very little is needed to make a happy life. - Marcus Aurelius",
30
+ "Waste no more time arguing what a good man should be, be one. - Marcus Aurelius",
31
+ "Well begun is half done. - Aristotle",
32
+ "When there is no desire, all things are at peace. - Laozi",
33
+ "Walk as if you are kissing the Earth with your feet. - Thich Nhat Hanh",
34
+ "Because you are alive, everything is possible. - Thich Nhat Hanh",
35
+ "Breathing in, I calm body and mind. Breathing out, I smile. - Thich Nhat Hanh",
36
+ "Life is available only in the present moment. - Thich Nhat Hanh",
37
+ "The best way to take care of the future is to take care of the present moment. - Thich Nhat Hanh",
38
+ "Nothing in life is to be feared, it is only to be understood. Now is the time to understand more, so that we may fear less. - Marie Curie",
39
+ "The biggest battle is the war against ignorance. - Mustafa Kemal Atatürk",
40
+ "Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead",
41
+ "You must be the change you wish to see in the world. - Mahatma Gandhi",
42
+ ];
43
+ export default class InspireCommand extends BaseCommand {
44
+ static commandName = "inspire";
45
+ static description = "";
46
+ static options = {
47
+ startApp: true,
48
+ };
49
+ async run() {
50
+ this.logger.info(quotes[Math.floor(Math.random() * quotes.length)]);
51
+ }
52
+ }
@@ -0,0 +1,4 @@
1
+ import { CommandMetaData, Command } from '@adonisjs/ace/types';
2
+
3
+ export function getMetaData(): Promise<CommandMetaData[]>
4
+ export function getCommand(metaData: CommandMetaData): Promise<Command | null>
@@ -0,0 +1,36 @@
1
+ import { readFile } from 'node:fs/promises'
2
+
3
+ /**
4
+ * In-memory cache of commands after they have been loaded
5
+ */
6
+ let commandsMetaData
7
+
8
+ /**
9
+ * Reads the commands from the "./commands.json" file. Since, the commands.json
10
+ * file is generated automatically, we do not have to validate its contents
11
+ */
12
+ export async function getMetaData() {
13
+ if (commandsMetaData) {
14
+ return commandsMetaData
15
+ }
16
+
17
+ const commandsIndex = await readFile(new URL('./commands.json', import.meta.url), 'utf-8')
18
+ commandsMetaData = JSON.parse(commandsIndex).commands
19
+
20
+ return commandsMetaData
21
+ }
22
+
23
+ /**
24
+ * Imports the command by lookingup its path from the commands
25
+ * metadata
26
+ */
27
+ export async function getCommand(metaData) {
28
+ const commands = await getMetaData()
29
+ const command = commands.find(({ commandName }) => metaData.commandName === commandName)
30
+ if (!command) {
31
+ return null
32
+ }
33
+
34
+ const { default: commandConstructor } = await import(new URL(command.filePath, import.meta.url).href)
35
+ return commandConstructor
36
+ }
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from "@adonisjs/core/ace";
2
+ import { CommandOptions } from "@adonisjs/core/types/ace";
3
+ import { Worker } from "../src/worker.js";
4
+ export default class SchedulerCommand extends BaseCommand {
5
+ static commandName: string;
6
+ static description: string;
7
+ static aliases: string[];
8
+ static options: CommandOptions;
9
+ watch: boolean;
10
+ tag: string;
11
+ worker: Worker;
12
+ prepare(): void;
13
+ run(): Promise<void>;
14
+ runAndWatch(): Promise<void>;
15
+ }
@@ -0,0 +1,74 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, flags } from "@adonisjs/core/ace";
8
+ import { spawn } from "child_process";
9
+ import chokidar from "chokidar";
10
+ import { Worker } from "../src/worker.js";
11
+ export default class SchedulerCommand extends BaseCommand {
12
+ static commandName = "scheduler:run";
13
+ static description = "";
14
+ static aliases = ["scheduler:work", "schedule:work", "schedule:run"];
15
+ static options = {
16
+ startApp: true,
17
+ staysAlive: true,
18
+ };
19
+ prepare() {
20
+ this.app.terminating(async () => {
21
+ if (this.worker)
22
+ await this.worker.stop();
23
+ });
24
+ }
25
+ async run() {
26
+ if (this.watch) {
27
+ return await this.runAndWatch();
28
+ }
29
+ this.worker = new Worker(this.app);
30
+ await this.worker.start(this.tag);
31
+ }
32
+ async runAndWatch() {
33
+ const logger = await this.app.container.make("logger");
34
+ let child;
35
+ const startProcess = () => {
36
+ if (child)
37
+ child.kill();
38
+ child = spawn("node", ["ace.js", "scheduler:run"], { stdio: "inherit" });
39
+ };
40
+ const watcher = chokidar.watch([this.app.appRoot.pathname], {
41
+ //@ts-ignore
42
+ ignored: (path, stats) => {
43
+ if (path.includes("node_modules") || path.includes(".git") || path.includes("build")) {
44
+ return true;
45
+ }
46
+ return stats?.isFile() && !path.endsWith(".ts") && !path.endsWith(".js");
47
+ },
48
+ persistent: true,
49
+ ignoreInitial: true,
50
+ });
51
+ let timeoutId;
52
+ watcher.on("all", (event, path) => {
53
+ if (typeof path === "string") {
54
+ logger.info(`File ${path.replace(this.app.appRoot.pathname, "")} changed (${event}), restarting...`);
55
+ }
56
+ clearTimeout(timeoutId);
57
+ timeoutId = setTimeout(() => {
58
+ startProcess();
59
+ }, 300);
60
+ });
61
+ startProcess();
62
+ this.app.terminating(async () => {
63
+ if (child)
64
+ child.kill();
65
+ process.exit();
66
+ });
67
+ }
68
+ }
69
+ __decorate([
70
+ flags.boolean({ description: "Restart the scheduler on file changes" })
71
+ ], SchedulerCommand.prototype, "watch", void 0);
72
+ __decorate([
73
+ flags.string({ description: "Tag for the scheduler", default: "default" })
74
+ ], SchedulerCommand.prototype, "tag", void 0);
@@ -0,0 +1,9 @@
1
+ import { BaseCommand } from "@adonisjs/core/ace";
2
+ import { CommandOptions } from "@adonisjs/core/types/ace";
3
+ export default class SchedulerCommand extends BaseCommand {
4
+ static commandName: string;
5
+ static description: string;
6
+ tag?: string;
7
+ static options: CommandOptions;
8
+ run(): Promise<void>;
9
+ }
@@ -0,0 +1,75 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, cliHelpers, flags } from "@adonisjs/core/ace";
8
+ import { CronExpressionParser } from "cron-parser";
9
+ import { DateTime } from "luxon";
10
+ import stringWidth from "string-width";
11
+ export default class SchedulerCommand extends BaseCommand {
12
+ static commandName = "scheduler:list";
13
+ static description = "";
14
+ static options = {
15
+ startApp: true,
16
+ };
17
+ async run() {
18
+ const schedule = await this.app.container.make("scheduler");
19
+ await schedule.boot();
20
+ const items = [];
21
+ for (let index = 0; index < schedule.items.length; index++) {
22
+ const command = schedule.items[index];
23
+ if (this.tag && command.config.tag !== this.tag) {
24
+ continue;
25
+ }
26
+ const commandName = command.type === "callback"
27
+ ? `Closure #${index + 1}`
28
+ : `node ace ${command.commandName}` + (command.commandArgs.length ? ` ${this.ui.colors.cyan(command.commandArgs.join(" "))}` : "");
29
+ let nextDueDate = null;
30
+ if (!command.config.enabled) {
31
+ nextDueDate = "Disabled";
32
+ }
33
+ else {
34
+ const cron = CronExpressionParser.parse(command.expression, {
35
+ tz: command.config.timezone,
36
+ });
37
+ nextDueDate = DateTime.fromJSDate(cron.next().toDate()).toRelative();
38
+ }
39
+ items.push({
40
+ expression: ` ${this.ui.colors.yellow(command.expression)} `,
41
+ commandName: ` ${commandName} `,
42
+ nextDueDate: this.ui.colors.dim(` Next Due: ${nextDueDate}`),
43
+ });
44
+ }
45
+ const expressions = items.map((item) => item.expression);
46
+ const largestExpressionLength = Math.max(...expressions.map((e) => stringWidth(e)));
47
+ const formattedExpressions = cliHelpers.justify(expressions, {
48
+ maxWidth: largestExpressionLength,
49
+ });
50
+ const commands = items.map((item) => item.commandName);
51
+ const largestCommandLength = Math.max(...commands.map((e) => stringWidth(e)));
52
+ const formattedCommands = cliHelpers.justify(commands, {
53
+ maxWidth: largestCommandLength,
54
+ paddingChar: this.ui.colors.dim("."),
55
+ });
56
+ const dates = items.map((item) => item.nextDueDate);
57
+ const largestDateLength = cliHelpers.TERMINAL_SIZE - (largestExpressionLength + largestCommandLength) - 10;
58
+ const formattedDates = cliHelpers.truncate(cliHelpers.justify(dates, {
59
+ maxWidth: largestDateLength,
60
+ align: "right",
61
+ paddingChar: this.ui.colors.dim("."),
62
+ }), {
63
+ maxWidth: largestDateLength,
64
+ });
65
+ for (let index = 0; index < formattedExpressions.length; index++) {
66
+ const expression = formattedExpressions[index];
67
+ const command = formattedCommands[index];
68
+ const date = formattedDates[index];
69
+ this.logger.log(`${expression}${command}${date}`);
70
+ }
71
+ }
72
+ }
73
+ __decorate([
74
+ flags.string({ description: "Filter by tag" })
75
+ ], SchedulerCommand.prototype, "tag", void 0);
@@ -0,0 +1,2 @@
1
+ import ConfigureCommand from "@adonisjs/core/commands/configure";
2
+ export declare function configure(command: ConfigureCommand): Promise<void>;
@@ -0,0 +1,23 @@
1
+ /*
2
+ |--------------------------------------------------------------------------
3
+ | Configure hook
4
+ |--------------------------------------------------------------------------
5
+ |
6
+ | The configure hook is called when someone runs "node ace configure <package>"
7
+ | command. You are free to perform any operations inside this function to
8
+ | configure the package.
9
+ |
10
+ | To make things easier, you have access to the underlying "ConfigureCommand"
11
+ | instance and you can use codemods to modify the source files.
12
+ |
13
+ */
14
+ import { stubsRoot } from "./stubs/main.js";
15
+ export async function configure(command) {
16
+ const codemods = await command.createCodemods();
17
+ await codemods.makeUsingStub(stubsRoot, "start/scheduler.stub", {});
18
+ await codemods.updateRcFile((rcFile) => {
19
+ rcFile.addProvider("@codenameryuu/adonis-scheduler/scheduler_provider", ["console"]);
20
+ rcFile.addCommand("@codenameryuu/adonis-scheduler/commands");
21
+ rcFile.addPreloadFile("#start/scheduler", ["console"]);
22
+ });
23
+ }
@@ -0,0 +1,5 @@
1
+ export { configure } from "./configure.js";
2
+ export { stubsRoot } from "./stubs/main.js";
3
+ export { Scheduler } from "./src/scheduler.js";
4
+ export { Worker } from "./src/worker.js";
5
+ export { schedule } from "./src/decorator.js";
package/build/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /*
2
+ |--------------------------------------------------------------------------
3
+ | Package entrypoint
4
+ |--------------------------------------------------------------------------
5
+ |
6
+ | Export values from the package entrypoint as you see fit.
7
+ |
8
+ */
9
+ export { configure } from "./configure.js";
10
+ export { stubsRoot } from "./stubs/main.js";
11
+ export { Scheduler } from "./src/scheduler.js";
12
+ export { Worker } from "./src/worker.js";
13
+ export { schedule } from "./src/decorator.js";
@@ -0,0 +1,12 @@
1
+ import type { ApplicationService } from "@adonisjs/core/types";
2
+ import { Scheduler } from "../src/scheduler.js";
3
+ declare module "@adonisjs/core/types" {
4
+ interface ContainerBindings {
5
+ scheduler: Scheduler;
6
+ }
7
+ }
8
+ export default class SchedulerProvider {
9
+ protected app: ApplicationService;
10
+ constructor(app: ApplicationService);
11
+ boot(): void;
12
+ }
@@ -0,0 +1,12 @@
1
+ import { Scheduler } from "../src/scheduler.js";
2
+ export default class SchedulerProvider {
3
+ app;
4
+ constructor(app) {
5
+ this.app = app;
6
+ }
7
+ boot() {
8
+ this.app.container.singleton("scheduler", () => {
9
+ return new Scheduler(this.app);
10
+ });
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ import type { Scheduler } from "../src/scheduler.js";
2
+ declare let scheduler: Scheduler;
3
+ export { scheduler as default };
@@ -0,0 +1,6 @@
1
+ import app from "@adonisjs/core/services/app";
2
+ let scheduler;
3
+ await app.booted(async () => {
4
+ scheduler = await app.container.make("scheduler");
5
+ });
6
+ export { scheduler as default };
@@ -0,0 +1,3 @@
1
+ import type { BaseCommand } from "@adonisjs/core/ace";
2
+ import { ScheduleCommand } from "./scheduler.js";
3
+ export declare function schedule(expression: string | ((s: ScheduleCommand) => ScheduleCommand), args?: string | string[]): <T extends typeof BaseCommand>(target: T) => T;
@@ -0,0 +1,13 @@
1
+ import { ScheduleCommand, Scheduler } from "./scheduler.js";
2
+ import { arrayWrap } from "./utils.js";
3
+ export function schedule(expression, args = []) {
4
+ return function (target) {
5
+ if (typeof expression === "string") {
6
+ Scheduler.__decorator_schedules.push(new ScheduleCommand(target.commandName, arrayWrap(args)).cron(expression));
7
+ }
8
+ else {
9
+ Scheduler.__decorator_schedules.push(expression(new ScheduleCommand(target.commandName, arrayWrap(args))));
10
+ }
11
+ return target;
12
+ };
13
+ }