UNPKG

adonisjs-jobs

Version:

Job processing for AdonisJS

46 lines (45 loc) 1.76 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { BaseCommand, flags } from '@adonisjs/core/ace'; import { Worker } from '../index.js'; export default class JobsListen extends BaseCommand { static commandName = 'jobs:listen'; static description = ''; static options = { startApp: true, staysAlive: true, }; async run() { const router = await this.app.container.make('router'); router.commit(); const worker = new Worker(this.app, { queues: this.queue, concurrency: this.concurrency, }); this.app.terminating(async () => { await worker.stop(); }); await worker.start(); } } __decorate([ flags.array({ description: 'The names of the queues to work', parse(input) { return input.flatMap((queue) => queue .split(',') .map((q) => q.trim()) .filter(Boolean)); }, }) ], JobsListen.prototype, "queue", void 0); __decorate([ flags.number({ description: 'Amount of jobs that a single worker is allowed to work on in parallel.', default: 1, }) ], JobsListen.prototype, "concurrency", void 0);