adonis-resque
Version:
Resque Queue for AdonisJS v6
66 lines (64 loc) • 1.71 kB
JavaScript
import {
importAllJobs
} from "../chunk-TOHLWYYX.js";
import {
getConfig
} from "../chunk-COFIVXLB.js";
import "../chunk-ZV4D6HN4.js";
import {
getConnection
} from "../chunk-VUECMJOZ.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) => {
if (!failure?.job?.job) {
throw failure.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