🔧 Bull + Redis task queue first draft

This commit is contained in:
2021-10-27 07:30:56 -07:00
parent 289b2ec3bd
commit 0ea5f78e98
3 changed files with 37 additions and 50 deletions

View File

@@ -6,7 +6,6 @@ import {
ServiceSchema,
Errors,
} from "moleculer";
import BullMQMixin from "moleculer-bull";
export default class LibraryQueueService extends Service {
@@ -23,13 +22,13 @@ export default class LibraryQueueService extends Service {
settings: {},
hooks: {},
queues: {
"mail.send": {
"process.import": {
async process(job) {
this.logger.info("New job received!", job.data);
this.logger.info(`Processing queue...`);
// const accounts = await this.broker.call('v1.users.list');
// this.logger.info(accounts);
const result = await this.broker.call('import.processAndImportToDB', job.data);
return Promise.resolve({
result,
id: job.id,
worker: process.pid,
});
@@ -40,36 +39,40 @@ export default class LibraryQueueService extends Service {
enqueue: {
rest: "POST /enqueue",
params: {},
async handler(ctx: Context<{}>) {
async handler(ctx: Context<{ extractionOptions: object, walkedFolders: object}>) {
console.log(ctx.params);
const job = await this.createJob("mail.send", {
blah: "blah",
});
const failed = await this.getQueue(
"mail.send"
).on("failed", async (job, error) => {
this.logger.error(
`An error occured in 'mail.send' queue on job id '${job.id}': ${error.message}`
);
});
const completed = await this.getQueue(
"mail.send"
).on("completed", async (job, res) => {
this.logger.info(
`Job with the id '${job.id}' completed.`
);
});
const stalled = await this.getQueue(
"mail.send"
).on("stalled", async (job) => {
this.logger.warn(
`The job with the id '${job} got stalled!`
);
extractionOptions: ctx.params.extractionOptions,
walkedFolders: ctx.params.walkedFolders,
});
},
},
},
methods: {},
async started(): Promise<any> {},
async started(): Promise<any> {
const failed = await this.getQueue(
"process.import"
).on("failed", async (job, error) => {
this.logger.error(
`An error occured in 'mail.send' queue on job id '${job.id}': ${error.message}`
);
});
const completed = await this.getQueue(
"process.import"
).on("completed", async (job, res) => {
this.logger.info(
`Job with the id '${job.id}' completed.`
);
});
const stalled = await this.getQueue(
"process.import"
).on("stalled", async (job) => {
this.logger.warn(
`The job with the id '${job} got stalled!`
);
});
},
},
schema
)