🐂 Added moleculer-bull
1. Added Bull MQ for enqueuing uncompression job 2. Added socket.io init code 3. Added a queue microservice
This commit is contained in:
@@ -98,21 +98,16 @@ export default class ApiService extends Service {
|
||||
this.io.on("connection", (client) => {
|
||||
this.logger.info("Client connected via websocket!");
|
||||
|
||||
client.on("action", (action, done) => {
|
||||
client.on("action", async (action) => {
|
||||
switch (action.type) {
|
||||
case "LS_IMPORT":
|
||||
this.broker
|
||||
.call(
|
||||
"libraryqueue.enqueue",
|
||||
action.data,
|
||||
{}
|
||||
)
|
||||
.then((res) => {
|
||||
if (done) {
|
||||
done(res);
|
||||
}
|
||||
})
|
||||
.catch((err) => this.logger.error(err));
|
||||
// 1. Send task to queue
|
||||
const result = await this.broker.call(
|
||||
"libraryqueue.enqueue",
|
||||
action.data,
|
||||
{}
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -126,7 +126,7 @@ export default class ImportService extends Service {
|
||||
{}
|
||||
);
|
||||
|
||||
return await dbImportResult;
|
||||
return { comicBookCoverMetadata, dbImportResult };
|
||||
} else {
|
||||
logger.info(
|
||||
`Comic: \"${walkedFolders.name}\" already exists in the database`
|
||||
@@ -377,7 +377,7 @@ export default class ImportService extends Service {
|
||||
new Promise((resolve, reject) =>
|
||||
https
|
||||
.get(
|
||||
`${apiDetailURL}?api_key=a5fa0663683df8145a85d694b5da4b87e1c92c69&format=json&limit=1&offset=0&field_list=id,name,description,image,first_issue,last_issue,publisher,count_of_issues,character_credits,person_credits,aliases`,
|
||||
`${apiDetailURL}?api_key=${process.env.COMICVINE_API_KEY}&format=json&limit=1&offset=0&field_list=id,name,description,image,first_issue,last_issue,publisher,count_of_issues,character_credits,person_credits,aliases`,
|
||||
(resp) => {
|
||||
let data = "";
|
||||
resp.on("data", (chunk) => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
Errors,
|
||||
} from "moleculer";
|
||||
import BullMQMixin from "moleculer-bull";
|
||||
const REDIS_URI = process.env.REDIS_URI || `redis://0.0.0.0:6379`;
|
||||
|
||||
export default class LibraryQueueService extends Service {
|
||||
public constructor(
|
||||
@@ -18,7 +19,7 @@ export default class LibraryQueueService extends Service {
|
||||
Service.mergeSchemas(
|
||||
{
|
||||
name: "libraryqueue",
|
||||
mixins: [BullMQMixin("redis://0.0.0.0:6379")],
|
||||
mixins: [BullMQMixin(REDIS_URI)],
|
||||
settings: {},
|
||||
hooks: {},
|
||||
queues: {
|
||||
@@ -27,6 +28,7 @@ export default class LibraryQueueService extends Service {
|
||||
this.logger.info("New job received!", job.data);
|
||||
this.logger.info(`Processing queue...`);
|
||||
const result = await this.broker.call('import.processAndImportToDB', job.data);
|
||||
|
||||
return Promise.resolve({
|
||||
result,
|
||||
id: job.id,
|
||||
@@ -40,11 +42,11 @@ export default class LibraryQueueService extends Service {
|
||||
rest: "POST /enqueue",
|
||||
params: {},
|
||||
async handler(ctx: Context<{ extractionOptions: object, walkedFolders: object}>) {
|
||||
console.log(ctx.params);
|
||||
const job = await this.createJob("mail.send", {
|
||||
return await this.createJob("process.import", {
|
||||
extractionOptions: ctx.params.extractionOptions,
|
||||
walkedFolders: ctx.params.walkedFolders,
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user