@outloud/adonis-scheduler 1.0.6 → 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 +113 -18
- package/build/_virtual/_@oxc-project_runtime@0.114.0/helpers/decorate.js +10 -0
- package/build/_virtual/_@oxc-project_runtime@0.114.0/helpers/decorateMetadata.js +7 -0
- package/build/commands/make_task.d.ts +16 -15
- package/build/commands/make_task.js +16 -38
- package/build/commands/scheduler_run.d.ts +12 -16
- package/build/commands/scheduler_run.js +28 -41
- package/build/providers/scheduler.provider.d.ts +18 -21
- package/build/providers/scheduler.provider.js +30 -36
- package/build/services/main.d.ts +4 -8
- package/build/services/main.js +6 -5
- package/build/src/command.task.js +18 -0
- package/build/src/config.d.ts +6 -0
- package/build/src/config.js +7 -0
- package/build/src/configure.d.ts +6 -0
- package/build/src/configure.js +15 -0
- package/build/src/helpers.js +9 -0
- package/build/src/index.d.ts +6 -0
- package/build/src/index.js +6 -0
- package/build/src/scheduler.d.ts +36 -0
- package/build/src/scheduler.js +147 -0
- package/build/src/task.d.ts +19 -0
- package/build/src/task.js +22 -0
- package/build/src/types.d.ts +60 -0
- package/build/stubs/config/scheduler.stub +1 -0
- package/package.json +14 -19
- package/build/chunk-7P6J5U6O.js +0 -25
- package/build/chunk-FOVOD6FP.js +0 -185
- package/build/chunk-SHUYVCID.js +0 -4
- package/build/command.task-GUNK3QFY.js +0 -22
- package/build/index.d.ts +0 -14
- package/build/index.js +0 -29
- package/build/scheduler-DO35E0Fu.d.ts +0 -99
- /package/{LICENSE → LICENSE.md} +0 -0
package/README.md
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
<h2><b>Adonis Scheduler</b></h2>
|
|
3
|
-
|
|
4
|
-
<p>
|
|
1
|
+
# AdonisJS Scheduler
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
Cron job scheduler for [AdonisJS](https://adonisjs.com/) 6/7.
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
</div>
|
|
5
|
+
<p>
|
|
10
6
|
|
|
7
|
+
[![typescript-image]][typescript-url]
|
|
8
|
+
[![npm-image]][npm-url]
|
|
9
|
+
[![npm-download-image]][npm-download-url]
|
|
10
|
+
[![license-image]][license-url]
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
[![npm-image]][npm-url] [![license-image]][license-url]
|
|
15
|
-
|
|
16
|
-
</div>
|
|
12
|
+
</p>
|
|
17
13
|
|
|
18
14
|
---
|
|
19
15
|
## Features
|
|
@@ -23,6 +19,7 @@
|
|
|
23
19
|
- Cancellation support for long-running tasks.
|
|
24
20
|
- Graceful shutdown.
|
|
25
21
|
- Global and task-level error handling.
|
|
22
|
+
- Auto-discovery of tasks.
|
|
26
23
|
|
|
27
24
|
## Getting Started
|
|
28
25
|
|
|
@@ -57,8 +54,12 @@ export default class TestTask extends Task {
|
|
|
57
54
|
```
|
|
58
55
|
|
|
59
56
|
### Register a task
|
|
57
|
+
For task to run it must be registered in the scheduler.
|
|
58
|
+
|
|
59
|
+
> [!NOTE]
|
|
60
|
+
> By default tasks are auto-discovered using the locations defined in config.
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
If you want to register tasks manually, you can register tasks in two ways: using the `start/scheduler.ts` preloaded file or in a provider's `start` method.
|
|
62
63
|
|
|
63
64
|
Using `start/scheduler.ts` file.
|
|
64
65
|
|
|
@@ -111,6 +112,77 @@ To run it as part of the **HTTP server**, set following env variable:
|
|
|
111
112
|
SCHEDULER_HTTP_SERVER=true
|
|
112
113
|
```
|
|
113
114
|
|
|
115
|
+
You can also create a custom worker command that runs the scheduler. This is useful if you want to add health checks or run other logic with the scheduler.
|
|
116
|
+
|
|
117
|
+
```ts [commands/worker.ts]
|
|
118
|
+
import { createServer, type Server as HttpServer } from 'node:http'
|
|
119
|
+
import { BaseCommand } from '@adonisjs/core/ace'
|
|
120
|
+
import { Server } from '@adonisjs/core/http'
|
|
121
|
+
import type { CommandOptions } from '@adonisjs/core/types/ace'
|
|
122
|
+
import { inject } from '@adonisjs/core'
|
|
123
|
+
import { Scheduler } from '@outloud/adonis-scheduler'
|
|
124
|
+
import type { ApplicationService } from '@adonisjs/core/types'
|
|
125
|
+
|
|
126
|
+
export default class extends BaseCommand {
|
|
127
|
+
static commandName = 'worker'
|
|
128
|
+
static description = 'Run a worker process.'
|
|
129
|
+
|
|
130
|
+
static options: CommandOptions = {
|
|
131
|
+
startApp: true,
|
|
132
|
+
staysAlive: true,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private server?: HttpServer
|
|
136
|
+
private scheduler?: Scheduler
|
|
137
|
+
|
|
138
|
+
prepare() {
|
|
139
|
+
this.app.terminating(() => this.server?.close())
|
|
140
|
+
this.app.terminating(() => this.scheduler?.stop())
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@inject()
|
|
144
|
+
async run(scheduler: Scheduler): Promise<void> {
|
|
145
|
+
this.scheduler = scheduler
|
|
146
|
+
|
|
147
|
+
await Promise.all([
|
|
148
|
+
this.startServer(),
|
|
149
|
+
this.scheduler.start(true),
|
|
150
|
+
])
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private async startServer() {
|
|
154
|
+
const server = await this.makeServer()
|
|
155
|
+
const httpServer = createServer(server.handle.bind(server))
|
|
156
|
+
this.server = httpServer
|
|
157
|
+
await server.boot()
|
|
158
|
+
|
|
159
|
+
server.setNodeServer(httpServer)
|
|
160
|
+
|
|
161
|
+
const host = process.env.HOST || '0.0.0.0'
|
|
162
|
+
const port = Number(process.env.PORT || '3000')
|
|
163
|
+
|
|
164
|
+
httpServer.once('listening', () => this.logger.info(`listening to http server, host: ${host}, port: ${port}`))
|
|
165
|
+
|
|
166
|
+
return httpServer.listen(port, host)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private async makeServer() {
|
|
170
|
+
const server = new Server(
|
|
171
|
+
this.app,
|
|
172
|
+
await this.app.container.make('encryption'),
|
|
173
|
+
await this.app.container.make('emitter'),
|
|
174
|
+
await this.app.container.make('logger'),
|
|
175
|
+
this.app.config.get<any>('app.http'),
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
const router = server.getRouter()
|
|
179
|
+
router.get('/health', () => ({ status: 'ok' }))
|
|
180
|
+
|
|
181
|
+
return server
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
114
186
|
## Locking
|
|
115
187
|
|
|
116
188
|
> [!NOTE]
|
|
@@ -157,20 +229,37 @@ export default class TestTask extends Task {
|
|
|
157
229
|
|
|
158
230
|
It's possible to globally handle errors for all your tasks or define custom error handler for each task.
|
|
159
231
|
|
|
232
|
+
### Global error handler
|
|
233
|
+
|
|
160
234
|
To register global error handler, you can use the `onError` method of the scheduler service. You can define it in `start/scheduler.ts` preloaded file.
|
|
161
235
|
This handler will run only if custom error handler is not defined in the task itself.
|
|
162
236
|
|
|
163
237
|
```ts
|
|
164
238
|
import logger from '@adonisjs/core/services/logger'
|
|
165
239
|
import scheduler from '@outloud/adonis-scheduler/services/main'
|
|
166
|
-
import { Sentry } from '@rlanz/sentry'
|
|
167
240
|
|
|
168
241
|
scheduler.onError((error, task) => {
|
|
169
242
|
logger.error(error)
|
|
170
|
-
Sentry.captureException(error)
|
|
171
243
|
})
|
|
172
244
|
```
|
|
173
245
|
|
|
246
|
+
Or you can listen to `scheduler:error` event using emitter.
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
import emitter from '@adonisjs/core/services/emitter'
|
|
250
|
+
import logger from '@adonisjs/core/services/logger'
|
|
251
|
+
|
|
252
|
+
emitter.on('scheduler:error', ({ error, task }) => {
|
|
253
|
+
logger.error(error)
|
|
254
|
+
})
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
> [!WARNING]
|
|
258
|
+
> When you register global error handler, the package will not throw any errors and it's your responsibility to log or handle them in the handler.
|
|
259
|
+
> If you don't register global error handler, the package will throw error and exit.
|
|
260
|
+
|
|
261
|
+
### Task-level error handler
|
|
262
|
+
|
|
174
263
|
Custom error handler can be defined in the task itself by implementing `onError` method.
|
|
175
264
|
|
|
176
265
|
```ts
|
|
@@ -183,8 +272,14 @@ export default class TestTask extends Task {
|
|
|
183
272
|
}
|
|
184
273
|
```
|
|
185
274
|
|
|
186
|
-
[npm-image]: https://
|
|
275
|
+
[npm-image]: https://badgen.net/npm/v/@outloud/adonis-scheduler/latest
|
|
187
276
|
[npm-url]: https://npmjs.org/package/@outloud/adonis-scheduler "npm"
|
|
188
277
|
|
|
189
|
-
[
|
|
190
|
-
[
|
|
278
|
+
[npm-download-image]: https://badgen.net/npm/dm/@outloud/adonis-scheduler
|
|
279
|
+
[npm-download-url]: https://npmcharts.com/compare/@outloud/adonis-scheduler?minimal=true "downloads"
|
|
280
|
+
|
|
281
|
+
[typescript-image]: https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white
|
|
282
|
+
[typescript-url]: https://www.typescriptlang.org "TypeScript"
|
|
283
|
+
|
|
284
|
+
[license-image]: https://img.shields.io/npm/l/@outloud/adonis-scheduler.svg?sanitize=true
|
|
285
|
+
[license-url]: LICENSE.md "license"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.114.0/helpers/decorate.js
|
|
2
|
+
function __decorate(decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { __decorate };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.114.0/helpers/decorateMetadata.js
|
|
2
|
+
function __decorateMetadata(k, v) {
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { __decorateMetadata };
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { BaseCommand } from
|
|
2
|
-
import { CommandOptions } from
|
|
1
|
+
import { BaseCommand } from "@adonisjs/core/ace";
|
|
2
|
+
import { CommandOptions } from "@adonisjs/core/types/ace";
|
|
3
3
|
|
|
4
|
+
//#region commands/make_task.d.ts
|
|
4
5
|
declare class MakeTask extends BaseCommand {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
static commandName: string;
|
|
7
|
+
static description: string;
|
|
8
|
+
static options: CommandOptions;
|
|
9
|
+
/**
|
|
10
|
+
* The name of the job file.
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Execute command
|
|
15
|
+
*/
|
|
16
|
+
run(): Promise<void>;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
export { MakeTask as default };
|
|
18
|
+
//#endregion
|
|
19
|
+
export { MakeTask as default };
|
|
@@ -1,42 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { BaseCommand, args } from
|
|
1
|
+
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.114.0/helpers/decorateMetadata.js";
|
|
2
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.114.0/helpers/decorate.js";
|
|
3
|
+
import { BaseCommand, args } from "@adonisjs/core/ace";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
-
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;
|
|
9
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
-
}
|
|
11
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
12
|
-
function _ts_metadata(k, v) {
|
|
13
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14
|
-
}
|
|
15
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
5
|
+
//#region commands/make_task.ts
|
|
16
6
|
var MakeTask = class extends BaseCommand {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* Execute command
|
|
27
|
-
*/
|
|
28
|
-
async run() {
|
|
29
|
-
const codemods = await this.createCodemods();
|
|
30
|
-
await codemods.makeUsingStub(import.meta.dirname + "/../stubs", "command/task.stub", {
|
|
31
|
-
entity: this.app.generators.createEntity(this.name)
|
|
32
|
-
});
|
|
33
|
-
}
|
|
7
|
+
static commandName = "make:task";
|
|
8
|
+
static description = "Make a new task class";
|
|
9
|
+
static options = { allowUnknownFlags: true };
|
|
10
|
+
/**
|
|
11
|
+
* Execute command
|
|
12
|
+
*/
|
|
13
|
+
async run() {
|
|
14
|
+
await (await this.createCodemods()).makeUsingStub(import.meta.dirname + "/../stubs", "command/task.stub", { entity: this.app.generators.createEntity(this.name) });
|
|
15
|
+
}
|
|
34
16
|
};
|
|
35
|
-
|
|
36
|
-
args.string({
|
|
37
|
-
description: "Name of the task"
|
|
38
|
-
}),
|
|
39
|
-
_ts_metadata("design:type", String)
|
|
40
|
-
], MakeTask.prototype, "name", void 0);
|
|
17
|
+
__decorate([args.string({ description: "Name of the task" }), __decorateMetadata("design:type", String)], MakeTask.prototype, "name", void 0);
|
|
41
18
|
|
|
42
|
-
|
|
19
|
+
//#endregion
|
|
20
|
+
export { MakeTask as default };
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import '@adonisjs/core/container';
|
|
5
|
-
import '@adonisjs/core/types';
|
|
6
|
-
import '@adonisjs/lock/types';
|
|
7
|
-
import '@adonisjs/core/logger';
|
|
8
|
-
import '@adonisjs/core/events';
|
|
1
|
+
import { Scheduler } from "../src/scheduler.js";
|
|
2
|
+
import { BaseCommand } from "@adonisjs/core/ace";
|
|
3
|
+
import { CommandOptions } from "@adonisjs/core/types/ace";
|
|
9
4
|
|
|
5
|
+
//#region commands/scheduler_run.d.ts
|
|
10
6
|
declare class SchedulerRun extends BaseCommand {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
static commandName: string;
|
|
8
|
+
static description: string;
|
|
9
|
+
static options: CommandOptions;
|
|
10
|
+
private scheduler?;
|
|
11
|
+
prepare(): void;
|
|
12
|
+
run(scheduler: Scheduler): Promise<void>;
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
export { SchedulerRun as default };
|
|
14
|
+
//#endregion
|
|
15
|
+
export { SchedulerRun as default };
|
|
@@ -1,46 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.114.0/helpers/decorateMetadata.js";
|
|
2
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.114.0/helpers/decorate.js";
|
|
3
|
+
import { Scheduler } from "../src/scheduler.js";
|
|
4
|
+
import { BaseCommand } from "@adonisjs/core/ace";
|
|
5
|
+
import { inject } from "@adonisjs/core";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10
|
-
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;
|
|
11
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
|
-
}
|
|
13
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
14
|
-
function _ts_metadata(k, v) {
|
|
15
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
16
|
-
}
|
|
17
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
7
|
+
//#region commands/scheduler_run.ts
|
|
8
|
+
var _ref;
|
|
18
9
|
var SchedulerRun = class extends BaseCommand {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.scheduler = scheduler;
|
|
34
|
-
await this.scheduler.start(true);
|
|
35
|
-
}
|
|
10
|
+
static commandName = "scheduler:run";
|
|
11
|
+
static description = "Run a scheduler";
|
|
12
|
+
static options = {
|
|
13
|
+
startApp: true,
|
|
14
|
+
staysAlive: true
|
|
15
|
+
};
|
|
16
|
+
scheduler;
|
|
17
|
+
prepare() {
|
|
18
|
+
this.app.terminating(() => this.scheduler?.stop());
|
|
19
|
+
}
|
|
20
|
+
async run(scheduler) {
|
|
21
|
+
this.scheduler = scheduler;
|
|
22
|
+
await this.scheduler.start(true);
|
|
23
|
+
}
|
|
36
24
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
]),
|
|
43
|
-
_ts_metadata("design:returntype", Promise)
|
|
25
|
+
__decorate([
|
|
26
|
+
inject(),
|
|
27
|
+
__decorateMetadata("design:type", Function),
|
|
28
|
+
__decorateMetadata("design:paramtypes", [typeof (_ref = typeof Scheduler !== "undefined" && Scheduler) === "function" ? _ref : Object]),
|
|
29
|
+
__decorateMetadata("design:returntype", Promise)
|
|
44
30
|
], SchedulerRun.prototype, "run", null);
|
|
45
31
|
|
|
46
|
-
|
|
32
|
+
//#endregion
|
|
33
|
+
export { SchedulerRun as default };
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import '@adonisjs/lock/types';
|
|
5
|
-
import '@adonisjs/core/logger';
|
|
6
|
-
import '@adonisjs/core/events';
|
|
1
|
+
import { SchedulerEvents } from "../src/types.js";
|
|
2
|
+
import { Scheduler } from "../src/scheduler.js";
|
|
3
|
+
import { ApplicationService } from "@adonisjs/core/types";
|
|
7
4
|
|
|
5
|
+
//#region providers/scheduler.provider.d.ts
|
|
8
6
|
declare class SchedulerProvider {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
protected app: ApplicationService;
|
|
8
|
+
private scheduler?;
|
|
9
|
+
constructor(app: ApplicationService);
|
|
10
|
+
private getConfig;
|
|
11
|
+
private getLocks;
|
|
12
|
+
register(): void;
|
|
13
|
+
ready(): Promise<void>;
|
|
14
|
+
shutdown(): Promise<void>;
|
|
17
15
|
}
|
|
18
16
|
declare module '@adonisjs/core/types' {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
17
|
+
interface ContainerBindings {
|
|
18
|
+
scheduler: Scheduler;
|
|
19
|
+
}
|
|
20
|
+
interface EventsList extends SchedulerEvents {}
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
export { SchedulerProvider as default };
|
|
22
|
+
//#endregion
|
|
23
|
+
export { SchedulerProvider as default };
|
|
@@ -1,40 +1,34 @@
|
|
|
1
|
-
import { Scheduler } from
|
|
2
|
-
import { __name } from '../chunk-SHUYVCID.js';
|
|
1
|
+
import { Scheduler } from "../src/scheduler.js";
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
//#region providers/scheduler.provider.ts
|
|
5
4
|
var SchedulerProvider = class {
|
|
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
|
-
await this.scheduler.start();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async shutdown() {
|
|
36
|
-
await this.scheduler?.stop();
|
|
37
|
-
}
|
|
5
|
+
scheduler;
|
|
6
|
+
constructor(app) {
|
|
7
|
+
this.app = app;
|
|
8
|
+
}
|
|
9
|
+
getConfig() {
|
|
10
|
+
return this.app.config.get("scheduler", {});
|
|
11
|
+
}
|
|
12
|
+
async getLocks() {
|
|
13
|
+
if (this.app.container.hasBinding("lock.manager")) return await this.app.container.make("lock.manager");
|
|
14
|
+
}
|
|
15
|
+
register() {
|
|
16
|
+
this.app.container.singleton(Scheduler, async () => {
|
|
17
|
+
return new Scheduler(this.getConfig(), this.app.container.createResolver(), await this.app.container.make("logger"), await this.app.container.make("emitter"), await this.getLocks());
|
|
18
|
+
});
|
|
19
|
+
this.app.container.alias("scheduler", Scheduler);
|
|
20
|
+
}
|
|
21
|
+
async ready() {
|
|
22
|
+
const config = this.getConfig();
|
|
23
|
+
if (this.app.getEnvironment() === "web" && config.httpServer) {
|
|
24
|
+
this.scheduler = await this.app.container.make(Scheduler);
|
|
25
|
+
await this.scheduler.start();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async shutdown() {
|
|
29
|
+
await this.scheduler?.stop();
|
|
30
|
+
}
|
|
38
31
|
};
|
|
39
32
|
|
|
40
|
-
|
|
33
|
+
//#endregion
|
|
34
|
+
export { SchedulerProvider as default };
|
package/build/services/main.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '@adonisjs/core/container';
|
|
3
|
-
import '@adonisjs/core/types';
|
|
4
|
-
import '@adonisjs/lock/types';
|
|
5
|
-
import '@adonisjs/core/logger';
|
|
6
|
-
import '@adonisjs/core/events';
|
|
1
|
+
import { Scheduler } from "../src/scheduler.js";
|
|
7
2
|
|
|
3
|
+
//#region services/main.d.ts
|
|
8
4
|
declare let scheduler: Scheduler;
|
|
9
|
-
|
|
10
|
-
export { scheduler as default };
|
|
5
|
+
//#endregion
|
|
6
|
+
export { scheduler as default };
|
package/build/services/main.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import app from '@adonisjs/core/services/app';
|
|
1
|
+
import app from "@adonisjs/core/services/app";
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
//#region services/main.ts
|
|
4
|
+
let scheduler;
|
|
5
5
|
await app?.booted(async () => {
|
|
6
|
-
|
|
6
|
+
scheduler = await app.container.make("scheduler");
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
export { scheduler as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Task } from "./task.js";
|
|
2
|
+
import ace from "@adonisjs/core/services/ace";
|
|
3
|
+
|
|
4
|
+
//#region src/command.task.ts
|
|
5
|
+
var CommandTask = class extends Task {
|
|
6
|
+
static command = [];
|
|
7
|
+
get name() {
|
|
8
|
+
return this.constructor.command.join(",");
|
|
9
|
+
}
|
|
10
|
+
async run() {
|
|
11
|
+
const [name, ...args] = this.constructor.command;
|
|
12
|
+
if (!name) throw new Error("No command name provided.");
|
|
13
|
+
await ace.exec(name, args);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { CommandTask };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
//#region src/configure.ts
|
|
4
|
+
async function configure(command) {
|
|
5
|
+
const codemods = await command.createCodemods();
|
|
6
|
+
await codemods.makeUsingStub(path.resolve(import.meta.dirname, "..", "stubs"), "config/scheduler.stub", {});
|
|
7
|
+
await codemods.defineEnvVariables({ SCHEDULER_HTTP_SERVER: false });
|
|
8
|
+
await codemods.defineEnvValidations({ variables: { SCHEDULER_HTTP_SERVER: `Env.schema.boolean.optional()` } });
|
|
9
|
+
await codemods.updateRcFile((rcFile) => {
|
|
10
|
+
rcFile.addProvider("@outloud/adonis-scheduler/provider").addCommand("@outloud/adonis-scheduler/commands");
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { configure };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SchedulerConfig, TaskOptions } from "./types.js";
|
|
2
|
+
import { Task } from "./task.js";
|
|
3
|
+
import { Scheduler } from "./scheduler.js";
|
|
4
|
+
import { configure } from "./configure.js";
|
|
5
|
+
import { defineConfig } from "./config.js";
|
|
6
|
+
export { Scheduler, type SchedulerConfig, Task, type TaskOptions, configure, defineConfig };
|