move worker debug port to 3001
All checks were successful
ci / build-image (push) Successful in 12s

This commit is contained in:
Jonathan Cremin 2025-05-20 13:58:46 +01:00
parent cf94976d3c
commit 82e336ba22

View file

@ -1,53 +1,54 @@
import co from 'co'; import co from "co";
import kue from 'kue'; import kue from "kue";
import Sentry from '@sentry/node'; import Sentry from "@sentry/node";
import debuglog from 'debug'; import debuglog from "debug";
import { inspect } from 'util'; import { inspect } from "util";
import models from './models/index.cjs'; import models from "./models/index.cjs";
import services from './lib/services.js'; import services from "./lib/services.js";
const debug = debuglog('combine.fm:worker'); const debug = debuglog("combine.fm:worker");
Sentry.init({ Sentry.init({
dsn: process.env.SENTRY_DSN, dsn: process.env.SENTRY_DSN
}); });
const queue = kue.createQueue({ const queue = kue.createQueue({
redis: process.env.REDIS_URL, redis: process.env.REDIS_URL
}); });
function search(data, done) { function search(data, done) {
const share = data.share; const share = data.share;
const service = services.find(item => data.service.id === item.id); const service = services.find(item => data.service.id === item.id);
debug(`Searching on: ${service.id}`); debug(`Searching on: ${service.id}`);
co(function* gen() { // eslint-disable-line no-loop-func co(function* gen() {
// eslint-disable-line no-loop-func
try { try {
const match = yield service.search(share); const match = yield service.search(share);
if (match.id) { if (match.id) {
models.match.create({ models.match.create({
trackId: share.type === 'track' ? share.id : null, trackId: share.type === "track" ? share.id : null,
albumId: share.type === 'album' ? share.id : null, albumId: share.type === "album" ? share.id : null,
externalId: match.id.toString(), externalId: match.id.toString(),
service: match.service, service: match.service,
name: match.name, name: match.name,
streamUrl: match.streamUrl, streamUrl: match.streamUrl,
purchaseUrl: match.purchaseUrl, purchaseUrl: match.purchaseUrl,
artworkSmall: match.artwork.small, artworkSmall: match.artwork.small,
artworkLarge: match.artwork.large, artworkLarge: match.artwork.large
}); });
} else { } else {
models.match.create({ models.match.create({
trackId: share.type === 'track' ? share.id : null, trackId: share.type === "track" ? share.id : null,
albumId: share.type === 'album' ? share.id : null, albumId: share.type === "album" ? share.id : null,
externalId: null, externalId: null,
service: match.service, service: match.service,
name: null, name: null,
streamUrl: null, streamUrl: null,
purchaseUrl: null, purchaseUrl: null,
artworkSmall: null, artworkSmall: null,
artworkLarge: null, artworkLarge: null
}); });
} }
return done(); return done();
@ -58,7 +59,7 @@ function search(data, done) {
Sentry.captureException(err); Sentry.captureException(err);
return done(err); return done(err);
} }
}).catch((err) => { }).catch(err => {
debug(`Error searching on: ${service.id}`); debug(`Error searching on: ${service.id}`);
debug(share); debug(share);
debug(inspect(err, { depth: 5 })); debug(inspect(err, { depth: 5 }));
@ -67,16 +68,18 @@ function search(data, done) {
}); });
} }
queue.process('search', 5, (job, done) => { queue.process("search", 5, (job, done) => {
search(job.data, done); search(job.data, done);
}); });
queue.process('search-backlog', 1, (job, ctx, done) => { queue.process("search-backlog", 1, (job, ctx, done) => {
search(job.data, done); search(job.data, done);
ctx.pause(7000, () => { ctx.pause(7000, () => {
console.log('Worker is paused... '); console.log("Worker is paused... ");
setTimeout(() => { ctx.resume(); }, 10000); setTimeout(() => {
ctx.resume();
}, 10000);
}); });
}); });
kue.app.listen(3000); kue.app.listen(3001);