@outloud/adonis-scheduler 1.0.7 → 1.1.1
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 +111 -20
- 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 -42
- package/build/providers/scheduler.provider.d.ts +18 -21
- package/build/providers/scheduler.provider.js +30 -37
- 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 +37 -0
- package/build/src/scheduler.js +154 -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/package.json +14 -18
- package/build/chunk-6VW5PUDE.js +0 -208
- package/build/chunk-OIXFFNQU.js +0 -28
- package/build/chunk-SHUYVCID.js +0 -4
- package/build/command.task-GALKWNLQ.js +0 -22
- package/build/index.d.ts +0 -14
- package/build/index.js +0 -29
- package/build/scheduler-vBDqaysB.d.ts +0 -103
- /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
|
|
@@ -60,9 +56,16 @@ export default class TestTask extends Task {
|
|
|
60
56
|
### Register a task
|
|
61
57
|
For task to run it must be registered in the scheduler.
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
#### Auto-discovery (recommended)
|
|
60
|
+
By default tasks are auto-discovered using the locations defined in `config/scheduler.ts`.
|
|
65
61
|
|
|
62
|
+
```ts
|
|
63
|
+
const schedulerConfig = defineConfig({
|
|
64
|
+
locations: ['./app/**/*.task.js'],
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Manual registration
|
|
66
69
|
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.
|
|
67
70
|
|
|
68
71
|
Using `start/scheduler.ts` file.
|
|
@@ -73,7 +76,7 @@ import scheduler from '@outloud/adonis-scheduler/services/main'
|
|
|
73
76
|
scheduler.register(() => import('../app/tasks/test.task.js'))
|
|
74
77
|
```
|
|
75
78
|
|
|
76
|
-
Or
|
|
79
|
+
Or in a any provider's `start` method.
|
|
77
80
|
|
|
78
81
|
```ts
|
|
79
82
|
import type { ApplicationService } from '@adonisjs/core/types'
|
|
@@ -116,6 +119,71 @@ To run it as part of the **HTTP server**, set following env variable:
|
|
|
116
119
|
SCHEDULER_HTTP_SERVER=true
|
|
117
120
|
```
|
|
118
121
|
|
|
122
|
+
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.
|
|
123
|
+
|
|
124
|
+
```ts [commands/worker.ts]
|
|
125
|
+
import { createServer, type Server as HttpServer } from 'node:http'
|
|
126
|
+
import { BaseCommand } from '@adonisjs/core/ace'
|
|
127
|
+
import type { CommandOptions } from '@adonisjs/core/types/ace'
|
|
128
|
+
import { inject } from '@adonisjs/core'
|
|
129
|
+
import { Scheduler } from '@outloud/adonis-scheduler'
|
|
130
|
+
|
|
131
|
+
export default class extends BaseCommand {
|
|
132
|
+
static commandName = 'worker'
|
|
133
|
+
static description = 'Run a worker process.'
|
|
134
|
+
|
|
135
|
+
static options: CommandOptions = {
|
|
136
|
+
startApp: true,
|
|
137
|
+
staysAlive: true,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private server?: HttpServer
|
|
141
|
+
private scheduler?: Scheduler
|
|
142
|
+
|
|
143
|
+
prepare() {
|
|
144
|
+
this.app.terminating(() => {
|
|
145
|
+
this.server?.close()
|
|
146
|
+
})
|
|
147
|
+
this.app.terminating(() => this.scheduler?.stop())
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@inject()
|
|
151
|
+
async run(scheduler: Scheduler): Promise<void> {
|
|
152
|
+
this.scheduler = scheduler
|
|
153
|
+
|
|
154
|
+
await Promise.all([
|
|
155
|
+
this.startServer(),
|
|
156
|
+
this.scheduler.start(true),
|
|
157
|
+
])
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private async startServer() {
|
|
161
|
+
const server = await this.makeServer()
|
|
162
|
+
await server.boot()
|
|
163
|
+
|
|
164
|
+
const httpServer = createServer(server.handle.bind(server))
|
|
165
|
+
server.setNodeServer(httpServer)
|
|
166
|
+
this.server = httpServer
|
|
167
|
+
|
|
168
|
+
const host = process.env.HOST || '0.0.0.0'
|
|
169
|
+
const port = Number(process.env.PORT || 3000)
|
|
170
|
+
|
|
171
|
+
httpServer.once('listening', () => this.logger.info(`listening to http server, host: ${host}, port: ${port}`))
|
|
172
|
+
|
|
173
|
+
return httpServer.listen(port, host)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private async makeServer() {
|
|
177
|
+
const server = await this.app.container.make('server')
|
|
178
|
+
const router = server.getRouter()
|
|
179
|
+
|
|
180
|
+
router.get('/health', () => ({ status: 'ok' }))
|
|
181
|
+
|
|
182
|
+
return server
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
119
187
|
## Locking
|
|
120
188
|
|
|
121
189
|
> [!NOTE]
|
|
@@ -162,20 +230,37 @@ export default class TestTask extends Task {
|
|
|
162
230
|
|
|
163
231
|
It's possible to globally handle errors for all your tasks or define custom error handler for each task.
|
|
164
232
|
|
|
233
|
+
### Global error handler
|
|
234
|
+
|
|
165
235
|
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.
|
|
166
236
|
This handler will run only if custom error handler is not defined in the task itself.
|
|
167
237
|
|
|
168
238
|
```ts
|
|
169
239
|
import logger from '@adonisjs/core/services/logger'
|
|
170
240
|
import scheduler from '@outloud/adonis-scheduler/services/main'
|
|
171
|
-
import { Sentry } from '@rlanz/sentry'
|
|
172
241
|
|
|
173
242
|
scheduler.onError((error, task) => {
|
|
174
243
|
logger.error(error)
|
|
175
|
-
Sentry.captureException(error)
|
|
176
244
|
})
|
|
177
245
|
```
|
|
178
246
|
|
|
247
|
+
Or you can listen to `scheduler:error` event using emitter.
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
import emitter from '@adonisjs/core/services/emitter'
|
|
251
|
+
import logger from '@adonisjs/core/services/logger'
|
|
252
|
+
|
|
253
|
+
emitter.on('scheduler:error', ({ error, task }) => {
|
|
254
|
+
logger.error(error)
|
|
255
|
+
})
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
> [!WARNING]
|
|
259
|
+
> 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.
|
|
260
|
+
> If you don't register global error handler, the package will throw error and exit.
|
|
261
|
+
|
|
262
|
+
### Task-level error handler
|
|
263
|
+
|
|
179
264
|
Custom error handler can be defined in the task itself by implementing `onError` method.
|
|
180
265
|
|
|
181
266
|
```ts
|
|
@@ -188,8 +273,14 @@ export default class TestTask extends Task {
|
|
|
188
273
|
}
|
|
189
274
|
```
|
|
190
275
|
|
|
191
|
-
[npm-image]: https://
|
|
276
|
+
[npm-image]: https://badgen.net/npm/v/@outloud/adonis-scheduler/latest
|
|
192
277
|
[npm-url]: https://npmjs.org/package/@outloud/adonis-scheduler "npm"
|
|
193
278
|
|
|
194
|
-
[
|
|
195
|
-
[
|
|
279
|
+
[npm-download-image]: https://badgen.net/npm/dm/@outloud/adonis-scheduler
|
|
280
|
+
[npm-download-url]: https://npmcharts.com/compare/@outloud/adonis-scheduler?minimal=true "downloads"
|
|
281
|
+
|
|
282
|
+
[typescript-image]: https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white
|
|
283
|
+
[typescript-url]: https://www.typescriptlang.org "TypeScript"
|
|
284
|
+
|
|
285
|
+
[license-image]: https://img.shields.io/npm/l/@outloud/adonis-scheduler.svg?sanitize=true
|
|
286
|
+
[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,47 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { inject } from
|
|
6
|
-
import { BaseCommand } from '@adonisjs/core/ace';
|
|
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";
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
11
|
-
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;
|
|
12
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
-
}
|
|
14
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
15
|
-
function _ts_metadata(k, v) {
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
17
|
-
}
|
|
18
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
7
|
+
//#region commands/scheduler_run.ts
|
|
8
|
+
var _ref;
|
|
19
9
|
var SchedulerRun = class extends BaseCommand {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.scheduler = scheduler;
|
|
35
|
-
await this.scheduler.start(true);
|
|
36
|
-
}
|
|
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
|
+
}
|
|
37
24
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
]),
|
|
44
|
-
_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)
|
|
45
30
|
], SchedulerRun.prototype, "run", null);
|
|
46
31
|
|
|
47
|
-
|
|
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,41 +1,34 @@
|
|
|
1
|
-
import { Scheduler } from
|
|
2
|
-
import '../chunk-OIXFFNQU.js';
|
|
3
|
-
import { __name } from '../chunk-SHUYVCID.js';
|
|
1
|
+
import { Scheduler } from "../src/scheduler.js";
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
//#region providers/scheduler.provider.ts
|
|
6
4
|
var SchedulerProvider = class {
|
|
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
|
-
await this.scheduler.start();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async shutdown() {
|
|
37
|
-
await this.scheduler?.stop();
|
|
38
|
-
}
|
|
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
|
+
}
|
|
39
31
|
};
|
|
40
32
|
|
|
41
|
-
|
|
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 };
|