@adonisjs/queue 0.1.1 → 0.2.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/build/commands/commands.json +1 -1
- package/build/commands/queue_scheduler_list.js +1 -1
- package/build/commands/queue_work.d.ts +1 -0
- package/build/commands/queue_work.js +7 -1
- package/build/providers/queue_provider.js +2 -2
- package/build/src/define_config.d.ts +2 -2
- package/build/src/types/main.d.ts +10 -0
- package/build/stubs/migration.stub +1 -1
- package/build/tests/helpers.d.ts +5 -0
- package/build/tests/helpers.js +51 -0
- package/build/tests/provider.spec.d.ts +1 -0
- package/build/tests/provider.spec.js +30 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commands":[{"commandName":"make:job","description":"Create a new job class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the job","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make_job.js"},{"commandName":"queue:scheduler:clear","description":"Remove all scheduled jobs","help":"","namespace":"queue","aliases":[],"flags":[],"args":[],"options":{"startApp":true},"filePath":"queue_scheduler_clear.js"},{"commandName":"queue:scheduler:list","description":"List all scheduled jobs","help":"","namespace":"queue","aliases":[],"flags":[{"name":"status","flagName":"status","required":false,"type":"string","description":"Filter by status (active, paused)","alias":"s"}],"args":[],"options":{"startApp":true},"filePath":"queue_scheduler_list.js"},{"commandName":"queue:scheduler:remove","description":"Remove a scheduled job by ID","help":"","namespace":"queue","aliases":[],"flags":[],"args":[{"name":"id","argumentName":"id","required":true,"description":"ID of the schedule to remove","type":"string"}],"options":{"startApp":true},"filePath":"queue_scheduler_remove.js"},{"commandName":"queue:work","description":"Start processing jobs from the queue","help":"","namespace":"queue","aliases":[],"flags":[{"name":"queue","flagName":"queue","required":false,"type":"string","description":"Comma-separated list of queues to process","alias":"q"}],"args":[],"options":{"startApp":true,"staysAlive":true},"filePath":"queue_work.js"}],"version":1}
|
|
1
|
+
{"commands":[{"commandName":"make:job","description":"Create a new job class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the job","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make_job.js"},{"commandName":"queue:scheduler:clear","description":"Remove all scheduled jobs","help":"","namespace":"queue","aliases":[],"flags":[],"args":[],"options":{"startApp":true},"filePath":"queue_scheduler_clear.js"},{"commandName":"queue:scheduler:list","description":"List all scheduled jobs","help":"","namespace":"queue","aliases":[],"flags":[{"name":"status","flagName":"status","required":false,"type":"string","description":"Filter by status (active, paused)","alias":"s"}],"args":[],"options":{"startApp":true},"filePath":"queue_scheduler_list.js"},{"commandName":"queue:scheduler:remove","description":"Remove a scheduled job by ID","help":"","namespace":"queue","aliases":[],"flags":[],"args":[{"name":"id","argumentName":"id","required":true,"description":"ID of the schedule to remove","type":"string"}],"options":{"startApp":true},"filePath":"queue_scheduler_remove.js"},{"commandName":"queue:work","description":"Start processing jobs from the queue","help":"","namespace":"queue","aliases":[],"flags":[{"name":"queue","flagName":"queue","required":false,"type":"string","description":"Comma-separated list of queues to process","alias":"q"},{"name":"concurrency","flagName":"concurrency","required":false,"type":"number","description":"Number of jobs to process concurrently","alias":"c"}],"args":[],"options":{"startApp":true,"staysAlive":true},"filePath":"queue_work.js"}],"version":1}
|
|
@@ -38,7 +38,7 @@ export default class QueueSchedulerList extends BaseCommand {
|
|
|
38
38
|
const lastRun = schedule.lastRunAt?.toISOString() ?? 'Never';
|
|
39
39
|
table.row([
|
|
40
40
|
schedule.id,
|
|
41
|
-
schedule.
|
|
41
|
+
schedule.name,
|
|
42
42
|
scheduleExpr,
|
|
43
43
|
schedule.status,
|
|
44
44
|
String(schedule.runCount),
|
|
@@ -32,10 +32,16 @@ export default class QueueWork extends BaseCommand {
|
|
|
32
32
|
router.commit();
|
|
33
33
|
const queues = this.queue ? this.queue.split(',').map((q) => q.trim()) : ['default'];
|
|
34
34
|
this.logger.info(`Starting worker for queues: ${queues.join(', ')}`);
|
|
35
|
-
const worker = new Worker(
|
|
35
|
+
const worker = new Worker({
|
|
36
|
+
...config,
|
|
37
|
+
...(this.concurrency && { concurrency: this.concurrency }),
|
|
38
|
+
});
|
|
36
39
|
await worker.start(queues);
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
__decorate([
|
|
40
43
|
flags.string({ description: 'Comma-separated list of queues to process', alias: 'q' })
|
|
41
44
|
], QueueWork.prototype, "queue", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
flags.number({ description: 'Number of jobs to process concurrently', alias: 'c' })
|
|
47
|
+
], QueueWork.prototype, "concurrency", void 0);
|
|
@@ -33,8 +33,8 @@ export default class QueueProvider {
|
|
|
33
33
|
* This enables automatic dependency injection for job classes.
|
|
34
34
|
*/
|
|
35
35
|
const jobFactory = config.jobFactory ??
|
|
36
|
-
(async (JobClass
|
|
37
|
-
return this.app.container.make(JobClass
|
|
36
|
+
(async (JobClass) => {
|
|
37
|
+
return this.app.container.make(JobClass);
|
|
38
38
|
});
|
|
39
39
|
const logger = await this.app.container.make('logger');
|
|
40
40
|
await QueueManager.init({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { QueueConfig } from './types/main.js';
|
|
2
2
|
/**
|
|
3
3
|
* Define queue configuration with type-safety.
|
|
4
4
|
*/
|
|
5
|
-
export declare function defineConfig(config:
|
|
5
|
+
export declare function defineConfig(config: QueueConfig): QueueConfig;
|
|
@@ -1 +1,11 @@
|
|
|
1
|
+
import type { ConfigProvider } from '@adonisjs/core/types';
|
|
2
|
+
import type { Adapter, QueueManagerConfig } from '@boringnode/queue/types';
|
|
1
3
|
export * from '@boringnode/queue/types';
|
|
4
|
+
type AdapterFactory = () => Adapter;
|
|
5
|
+
/**
|
|
6
|
+
* AdonisJS-specific queue configuration that supports both
|
|
7
|
+
* direct adapter factories and config providers.
|
|
8
|
+
*/
|
|
9
|
+
export interface QueueConfig extends Omit<QueueManagerConfig, 'adapters'> {
|
|
10
|
+
adapters: Record<string, AdapterFactory | ConfigProvider<AdapterFactory>>;
|
|
11
|
+
}
|
|
@@ -30,7 +30,7 @@ export default class extends BaseSchema {
|
|
|
30
30
|
this.schema.createTable('queue_schedules', (table) => {
|
|
31
31
|
table.string('id', 255).primary()
|
|
32
32
|
table.string('status', 50).notNullable().defaultTo('active')
|
|
33
|
-
table.string('
|
|
33
|
+
table.string('name', 255).notNullable()
|
|
34
34
|
table.text('payload').notNullable()
|
|
35
35
|
table.string('cron_expression', 255).nullable()
|
|
36
36
|
table.bigint('every_ms').unsigned().nullable()
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AppEnvironments } from '@adonisjs/core/types/app';
|
|
2
|
+
import { defineConfig } from '../index.js';
|
|
3
|
+
export declare function setupApp(env?: AppEnvironments, config?: {
|
|
4
|
+
queue?: ReturnType<typeof defineConfig>;
|
|
5
|
+
}): Promise<import("@adonisjs/core/types").ApplicationService>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/queue
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
10
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
11
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
12
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return path;
|
|
16
|
+
};
|
|
17
|
+
import { getActiveTest } from '@japa/runner';
|
|
18
|
+
import { IgnitorFactory } from '@adonisjs/core/factories';
|
|
19
|
+
import { defineConfig, drivers } from '../index.js';
|
|
20
|
+
const BASE_URL = new URL('./tmp/', import.meta.url);
|
|
21
|
+
export async function setupApp(env, config = {}) {
|
|
22
|
+
const ignitor = new IgnitorFactory()
|
|
23
|
+
.withCoreProviders()
|
|
24
|
+
.withCoreConfig()
|
|
25
|
+
.merge({
|
|
26
|
+
config: {
|
|
27
|
+
queue: config.queue ||
|
|
28
|
+
defineConfig({
|
|
29
|
+
default: 'sync',
|
|
30
|
+
adapters: {
|
|
31
|
+
sync: drivers.sync(),
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
rcFileContents: {
|
|
36
|
+
providers: [() => import('../providers/queue_provider.js')],
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
.create(BASE_URL, {
|
|
40
|
+
importer: (filePath) => {
|
|
41
|
+
if (filePath.startsWith('./') || filePath.startsWith('../')) {
|
|
42
|
+
return import(__rewriteRelativeImportExtension(new URL(filePath, BASE_URL).href));
|
|
43
|
+
}
|
|
44
|
+
return import(__rewriteRelativeImportExtension(filePath));
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const app = ignitor.createApp(env || 'web');
|
|
48
|
+
await app.init().then(() => app.boot());
|
|
49
|
+
getActiveTest()?.cleanup(() => app.terminate());
|
|
50
|
+
return app;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/queue
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import { test } from '@japa/runner';
|
|
10
|
+
import { setupApp } from './helpers.js';
|
|
11
|
+
test.group('Provider', () => {
|
|
12
|
+
test('should resolve queue manager from container', async ({ assert }) => {
|
|
13
|
+
const app = await setupApp();
|
|
14
|
+
const queueManager = await app.container.make('queue.manager');
|
|
15
|
+
assert.isDefined(queueManager);
|
|
16
|
+
assert.isFunction(queueManager.use);
|
|
17
|
+
assert.isFunction(queueManager.destroy);
|
|
18
|
+
});
|
|
19
|
+
test('should resolve adapters from config providers', async ({ assert }) => {
|
|
20
|
+
const app = await setupApp();
|
|
21
|
+
const queueManager = await app.container.make('queue.manager');
|
|
22
|
+
assert.isDefined(queueManager);
|
|
23
|
+
});
|
|
24
|
+
test('should shutdown queue manager when app terminates', async ({ assert }) => {
|
|
25
|
+
const app = await setupApp();
|
|
26
|
+
const queueManager = await app.container.make('queue.manager');
|
|
27
|
+
assert.isDefined(queueManager);
|
|
28
|
+
await app.terminate();
|
|
29
|
+
});
|
|
30
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/queue",
|
|
3
3
|
"description": "Queue system for AdonisJS powered by @boringnode/queue",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.11.1"
|
|
7
7
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"version": "npm run build"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@boringnode/queue": "^0.
|
|
38
|
+
"@boringnode/queue": "^0.2.0",
|
|
39
39
|
"@poppinss/utils": "^6.10.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|