Migrating to workers, renaming service
This commit is contained in:
parent
850584ff36
commit
a6cd5f4266
29 changed files with 5542 additions and 611 deletions
64
worker.js
Normal file
64
worker.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
import co from 'co';
|
||||
import kue from 'kue';
|
||||
import raven from 'raven';
|
||||
|
||||
import models from './models';
|
||||
import services from './lib/services';
|
||||
import { find, create, findMatchesAsync } from './lib/share';
|
||||
|
||||
raven.config(process.env.SENTRY_DSN).install();
|
||||
|
||||
const queue = kue.createQueue({
|
||||
redis: {
|
||||
host: 'redis',
|
||||
},
|
||||
});
|
||||
|
||||
function search(share, done) {
|
||||
for (const service of services) {
|
||||
if (service.id === share.service) {
|
||||
continue; // eslint-disable-line no-continue
|
||||
}
|
||||
co(function* gen() { // eslint-disable-line no-loop-func
|
||||
const match = yield service.search(share);
|
||||
|
||||
if (match.id) {
|
||||
models.match.create({
|
||||
trackId: share.type === 'track' ? share.id : null,
|
||||
albumId: share.type === 'album' ? share.id : null,
|
||||
externalId: match.id.toString(),
|
||||
service: match.service,
|
||||
name: match.name,
|
||||
streamUrl: match.streamUrl,
|
||||
purchaseUrl: match.purchaseUrl,
|
||||
artworkSmall: match.artwork.small,
|
||||
artworkLarge: match.artwork.large,
|
||||
});
|
||||
} else {
|
||||
models.match.create({
|
||||
trackId: share.type === 'track' ? share.id : null,
|
||||
albumId: share.type === 'album' ? share.id : null,
|
||||
externalId: null,
|
||||
service: match.service,
|
||||
name: null,
|
||||
streamUrl: null,
|
||||
purchaseUrl: null,
|
||||
artworkSmall: null,
|
||||
artworkLarge: null,
|
||||
});
|
||||
}
|
||||
}).catch((err) => {
|
||||
raven.captureException(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return done();
|
||||
}
|
||||
|
||||
queue.process('search', (job, done) => {
|
||||
search(job.data, done);
|
||||
});
|
||||
|
||||
|
||||
kue.app.listen(3000);
|
Loading…
Add table
Add a link
Reference in a new issue