UNPKG

@fellas/adonisjs-resque

Version:
63 lines (61 loc) 1.64 kB
import { importAllJobs } from "../chunk-NKW4PRQD.js"; import { getConfig } from "../chunk-MZLOY7HF.js"; import "../chunk-ASV6JZ7C.js"; import { getConnection } from "../chunk-5SDUSZZN.js"; import "../chunk-EUXUH3YW.js"; // queue.ts import { Queue } from "node-resque"; function createQueue(jobs) { return new Queue({ connection: getConnection() }, jobs); } // providers/resque_provider.ts var ResqueProvider = class { constructor(app) { this.app = app; } command; async register() { this.app.container.singleton("queue", async () => { const jobs = await importAllJobs(); const queue = createQueue(jobs); await queue.connect(); return queue; }); const emitter = await this.app.container.make("emitter"); emitter.on("resque:failure", async (failure) => { return failure.job.job.onFailure(failure); }); } async start() { if (this.app.getEnvironment() === "web" && getConfig("runWorkerInWebEnv")) { const ace = await this.app.container.make("ace"); await ace.boot(); if (ace.getCommand("resque:start")) { this.command = await ace.exec("resque:start", []); if (this.command.exitCode !== 0 || this.command.error) { const error = this.command.error || new Error(`Failed to start command resque:start`); throw error; } } } } async shutdown() { if (this.command) { await this.command.terminate(); } const queue = await this.app.container.make("queue"); await queue.end(); } }; export { ResqueProvider as default }; //# sourceMappingURL=resque_provider.js.map