@adonisjs/queue 0.2.2 → 0.3.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.
@@ -13,7 +13,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
13
13
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14
14
  };
15
15
  import { flags, BaseCommand } from '@adonisjs/core/ace';
16
- import { resolveAdapters } from '../src/utils.js';
16
+ import { resolveAdapters, resolveJobFactory } from '../src/utils.js';
17
17
  export default class QueueWork extends BaseCommand {
18
18
  static commandName = 'queue:work';
19
19
  static description = 'Start processing jobs from the queue';
@@ -34,10 +34,7 @@ export default class QueueWork extends BaseCommand {
34
34
  const resolvedAdapters = await resolveAdapters(config, this.app);
35
35
  const queues = this.queue ? this.queue.split(',').map((q) => q.trim()) : ['default'];
36
36
  this.logger.info(`Starting worker for queues: ${queues.join(', ')}`);
37
- const jobFactory = config.jobFactory ??
38
- (async (JobClass) => {
39
- return this.app.container.make(JobClass);
40
- });
37
+ const jobFactory = resolveJobFactory(config, this.app);
41
38
  const worker = new Worker({
42
39
  ...config,
43
40
  adapters: resolvedAdapters,
@@ -4,5 +4,6 @@ export default class QueueProvider {
4
4
  protected app: ApplicationService;
5
5
  constructor(app: ApplicationService);
6
6
  register(): void;
7
+ boot(): Promise<void>;
7
8
  shutdown(): Promise<void>;
8
9
  }
@@ -7,7 +7,7 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import '../src/types/extended.js';
10
- import { resolveAdapters } from '../src/utils.js';
10
+ import { resolveAdapters, resolveJobFactory } from '../src/utils.js';
11
11
  export default class QueueProvider {
12
12
  app;
13
13
  constructor(app) {
@@ -22,10 +22,7 @@ export default class QueueProvider {
22
22
  * Inject jobFactory if not already defined.
23
23
  * This enables automatic dependency injection for job classes.
24
24
  */
25
- const jobFactory = config.jobFactory ??
26
- (async (JobClass) => {
27
- return this.app.container.make(JobClass);
28
- });
25
+ const jobFactory = resolveJobFactory(config, this.app);
29
26
  const logger = await this.app.container.make('logger');
30
27
  await QueueManager.init({
31
28
  ...config,
@@ -36,6 +33,9 @@ export default class QueueProvider {
36
33
  return QueueManager;
37
34
  });
38
35
  }
36
+ async boot() {
37
+ await this.app.container.make('queue.manager');
38
+ }
39
39
  async shutdown() {
40
40
  const queueManager = await this.app.container.make('queue.manager');
41
41
  await queueManager.destroy();
@@ -1,7 +1,6 @@
1
1
  import type { ConfigProvider } from '@adonisjs/core/types';
2
2
  import type { RedisConnections } from '@adonisjs/redis/types';
3
- import type { Adapter } from '@boringnode/queue/types';
4
- type AdapterFactory = () => Adapter;
3
+ import type { AdapterFactory } from '@boringnode/queue/types';
5
4
  /**
6
5
  * Queue drivers that integrate with AdonisJS services.
7
6
  *
@@ -30,4 +29,3 @@ export declare const drivers: {
30
29
  */
31
30
  sync: () => ConfigProvider<AdapterFactory>;
32
31
  };
33
- export {};
@@ -1,7 +1,6 @@
1
1
  import type { ConfigProvider } from '@adonisjs/core/types';
2
- import type { Adapter, QueueManagerConfig } from '@boringnode/queue/types';
2
+ import type { AdapterFactory, QueueManagerConfig } from '@boringnode/queue/types';
3
3
  export * from '@boringnode/queue/types';
4
- type AdapterFactory = () => Adapter;
5
4
  /**
6
5
  * AdonisJS-specific queue configuration that supports both
7
6
  * direct adapter factories and config providers.
@@ -1,6 +1,5 @@
1
1
  import type { ApplicationService } from '@adonisjs/core/types';
2
- import type { QueueConfig } from './types/main.js';
3
- type AdapterFactory = () => any;
2
+ import type { AdapterFactory, JobFactory, QueueConfig } from './types/main.js';
4
3
  /**
5
4
  * Resolve adapter factories from config providers.
6
5
  *
@@ -11,4 +10,4 @@ type AdapterFactory = () => any;
11
10
  * This function normalizes them all to factory functions.
12
11
  */
13
12
  export declare function resolveAdapters(config: QueueConfig, app: ApplicationService): Promise<Record<string, AdapterFactory>>;
14
- export {};
13
+ export declare function resolveJobFactory(config: QueueConfig, app: ApplicationService): JobFactory;
@@ -27,3 +27,6 @@ export async function resolveAdapters(config, app) {
27
27
  }
28
28
  return resolvedAdapters;
29
29
  }
30
+ export function resolveJobFactory(config, app) {
31
+ return config.jobFactory ?? ((jobClass) => app.container.make(jobClass));
32
+ }
@@ -13,15 +13,18 @@ export default class extends BaseSchema {
13
13
  this.schema.createTable('queue_jobs', (table) => {
14
14
  table.string('id', 255).notNullable()
15
15
  table.string('queue', 255).notNullable()
16
- table.enu('status', ['pending', 'active', 'delayed']).notNullable()
16
+ table.enu('status', ['pending', 'active', 'delayed', 'completed', 'failed']).notNullable()
17
17
  table.text('data').notNullable()
18
18
  table.bigint('score').unsigned().nullable()
19
19
  table.string('worker_id', 255).nullable()
20
20
  table.bigint('acquired_at').unsigned().nullable()
21
21
  table.bigint('execute_at').unsigned().nullable()
22
+ table.bigint('finished_at').unsigned().nullable()
23
+ table.text('error').nullable()
22
24
  table.primary(['id', 'queue'])
23
25
  table.index(['queue', 'status', 'score'])
24
26
  table.index(['queue', 'status', 'execute_at'])
27
+ table.index(['queue', 'status', 'finished_at'])
25
28
  })
26
29
 
27
30
  /**
@@ -41,7 +44,7 @@ export default class extends BaseSchema {
41
44
  table.integer('run_count').unsigned().notNullable().defaultTo(0)
42
45
  table.timestamp('next_run_at').nullable()
43
46
  table.timestamp('last_run_at').nullable()
44
- table.timestamp('created_at').notNullable().defaultTo(this.#connection.fn.now())
47
+ table.timestamp('created_at').notNullable().defaultTo(this.now())
45
48
  table.index(['status', 'next_run_at'])
46
49
  })
47
50
  }
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.2.2",
4
+ "version": "0.3.0",
5
5
  "engines": {
6
6
  "node": ">=20.11.1"
7
7
  },
@@ -35,30 +35,30 @@
35
35
  "version": "npm run build"
36
36
  },
37
37
  "dependencies": {
38
- "@boringnode/queue": "^0.2.0",
38
+ "@boringnode/queue": "^0.3.1",
39
39
  "@poppinss/utils": "^6.10.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@adonisjs/assembler": "^7.8.2",
43
- "@adonisjs/core": "^6.17.2",
44
- "@adonisjs/eslint-config": "^2.0.0",
45
- "@adonisjs/lucid": "^21.7.0",
46
- "@adonisjs/prettier-config": "^1.4.4",
43
+ "@adonisjs/core": "^6.19.3",
44
+ "@adonisjs/eslint-config": "^2.1.2",
45
+ "@adonisjs/lucid": "^21.8.2",
46
+ "@adonisjs/prettier-config": "^1.4.5",
47
47
  "@adonisjs/redis": "^9.2.0",
48
- "@adonisjs/tsconfig": "^1.4.0",
49
- "@japa/assert": "^4.0.1",
48
+ "@adonisjs/tsconfig": "^1.4.1",
49
+ "@japa/assert": "^4.2.0",
50
50
  "@japa/file-system": "^2.3.2",
51
- "@japa/runner": "^4.2.0",
51
+ "@japa/runner": "^4.5.0",
52
52
  "@poppinss/ts-exec": "^1.4.1",
53
53
  "@release-it/conventional-changelog": "^10.0.4",
54
- "@types/node": "^20.17.22",
54
+ "@types/node": "^20.19.29",
55
55
  "c8": "^10.1.3",
56
56
  "copyfiles": "^2.4.1",
57
57
  "del-cli": "^6.0.0",
58
- "eslint": "^9.23.0",
59
- "prettier": "^3.5.3",
60
- "release-it": "^19.2.2",
61
- "typescript": "^5.8.2"
58
+ "eslint": "^9.39.2",
59
+ "prettier": "^3.8.0",
60
+ "release-it": "^19.2.3",
61
+ "typescript": "^5.9.3"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@adonisjs/assembler": "^7.0.0 || ^8.0.0 || ^8.0.0-next",