Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: "Close stale issues and PRs"
name: 'Close stale issues and PRs'
on:
schedule:
- cron: "30 0 * * *"
- cron: '30 0 * * *'

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
stale-issue-message: "This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue"
stale-pr-message: "This pull request has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still intend to submit this pull request"
close-issue-message: "This issue has been automatically closed because it has been inactive for more than 4 weeks. Please reopen if you still need help on this issue"
close-pr-message: "This pull request has been automatically closed because it has been inactive for more than 4 weeks. Please reopen if you still intend to submit this pull request"
stale-issue-message: 'This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue'
stale-pr-message: 'This pull request has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still intend to submit this pull request'
close-issue-message: 'This issue has been automatically closed because it has been inactive for more than 4 weeks. Please reopen if you still need help on this issue'
close-pr-message: 'This pull request has been automatically closed because it has been inactive for more than 4 weeks. Please reopen if you still intend to submit this pull request'
days-before-stale: 21
days-before-close: 5
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ In order to ensure that the AdonisJS community is welcoming to all, please revie
AdonisJS Queue is open-sourced software licensed under the [MIT license](LICENSE.md).

[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/queue/checks.yml?style=for-the-badge
[gh-workflow-url]: https://github.com/adonisjs/queue/actions/workflows/checks.yml "Github action"

[gh-workflow-url]: https://github.com/adonisjs/queue/actions/workflows/checks.yml 'Github action'
[npm-image]: https://img.shields.io/npm/v/@adonisjs/queue/latest.svg?style=for-the-badge&logo=npm
[npm-url]: https://www.npmjs.com/package/@adonisjs/queue/v/latest "npm"

[npm-url]: https://www.npmjs.com/package/@adonisjs/queue/v/latest 'npm'
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript

[license-url]: LICENSE.md
[license-image]: https://img.shields.io/github/license/adonisjs/queue?style=for-the-badge
10 changes: 5 additions & 5 deletions commands/queue_work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { flags, BaseCommand } from '@adonisjs/core/ace'
import { resolveAdapters, resolveJobFactory } from '../src/utils.js'
import type { CommandOptions } from '@adonisjs/core/types/ace'
import { resolveAdapters, resolveJobFactory } from '../src/utils.js'
import type { QueueConfig, QueueManagerConfig } from '../src/types/main.js'

export default class QueueWork extends BaseCommand {
Expand All @@ -30,8 +30,9 @@ export default class QueueWork extends BaseCommand {
async run() {
const { Worker } = await import('@boringnode/queue')
const config = this.app.config.get<QueueConfig>('queue')
const queueManager = await this.app.container.make('queue.manager')
const logger = await this.app.container.make('logger')
const QueueManager = await this.app.container.make('queue.manager')
await QueueManager.start()

/**
* Commit the router to ensure all routes are registered.
Expand All @@ -45,12 +46,11 @@ export default class QueueWork extends BaseCommand {
const queues = this.queue ? this.queue.split(',').map((q) => q.trim()) : ['default']

this.logger.info(`Starting worker for queues: ${queues.join(', ')}`)
const jobFactory = resolveJobFactory(config, this.app)

const workerConfig = {
...config,
adapters: resolvedAdapters,
jobFactory,
jobFactory: resolveJobFactory(config, this.app),
logger: config.logger ?? logger,
worker: {
...config.worker,
Expand All @@ -63,7 +63,7 @@ export default class QueueWork extends BaseCommand {
try {
await worker.start(queues)
} finally {
await queueManager.destroy()
await QueueManager.destroy()
}
}
}
44 changes: 19 additions & 25 deletions providers/queue_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,40 @@
* file that was distributed with this source code.
*/

import '../src/types/extended.js'
import { resolveAdapters, resolveJobFactory } from '../src/utils.js'
import type { ApplicationService } from '@adonisjs/core/types'
import type { QueueConfig } from '../src/types/main.js'

import '../src/types/extended.js'
import { initQueue } from '../src/utils.ts'
import { type QueueConfig } from '../src/types/main.ts'

export default class QueueProvider {
constructor(protected app: ApplicationService) {}

register() {
this.app.container.singleton('queue.manager', async () => {
const { QueueManager } = await import('@boringnode/queue')
const config = this.app.config.get<QueueConfig>('queue')

const resolvedAdapters = await resolveAdapters(config, this.app)

/**
* Inject jobFactory if not already defined.
* This enables automatic dependency injection for job classes.
*/
const jobFactory = resolveJobFactory(config, this.app)

const logger = await this.app.container.make('logger')

await QueueManager.init({
...config,
adapters: resolvedAdapters,
jobFactory,
logger: config.logger ?? (logger as any),
})
;(QueueManager as any)['start'] = async () => {
const config = this.app.config.get<QueueConfig>('queue')
const logger = await this.app.container.make('logger')
return initQueue(QueueManager, this.app, config, logger)
}

return QueueManager
return QueueManager as typeof QueueManager & {
start(): Promise<void>
}
})
}

async boot() {
await this.app.container.make('queue.manager')
async start() {
if (this.app.getEnvironment() !== 'console') {
const QueueManager = await this.app.container.make('queue.manager')
await QueueManager.start()
}
}

async shutdown() {
const queueManager = await this.app.container.make('queue.manager')
await queueManager.destroy()
const QueueManager = await this.app.container.make('queue.manager')
await QueueManager.destroy()
}
}
4 changes: 3 additions & 1 deletion src/types/extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type { QueueManager } from '@boringnode/queue'

declare module '@adonisjs/core/types' {
export interface ContainerBindings {
'queue.manager': typeof QueueManager
'queue.manager': typeof QueueManager & {
start(): Promise<void>
}
}
}
19 changes: 19 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* file that was distributed with this source code.
*/

import { type Logger } from '@adonisjs/core/logger'
import type { ApplicationService } from '@adonisjs/core/types'
import type { QueueManager as QueueManagerSingleton } from '@boringnode/queue'
import type { AdapterFactory, JobFactory, QueueConfig } from './types/main.js'

/**
Expand Down Expand Up @@ -39,3 +41,20 @@ export async function resolveAdapters(
export function resolveJobFactory(config: QueueConfig, app: ApplicationService): JobFactory {
return config.jobFactory ?? ((jobClass: any) => app.container.make(jobClass))
}

export async function initQueue(
manager: typeof QueueManagerSingleton,
app: ApplicationService,
config: QueueConfig,
logger: Logger
) {
const resolvedAdapters = await resolveAdapters(config, app)
const jobFactory = resolveJobFactory(config, app)

await manager.init({
...config,
adapters: resolvedAdapters,
jobFactory,
logger: config.logger ?? logger,
})
}
Loading