diff --git a/lib/services/google/index.js b/lib/services/google/index.js index 10e57cd..57fd534 100644 --- a/lib/services/google/index.js +++ b/lib/services/google/index.js @@ -4,7 +4,7 @@ import PlayMusic from 'playmusic'; import debuglog from 'debug'; import urlMatch from './url'; -const debug = debuglog('combine.fm'); +const debug = debuglog('combine.fm:google'); const pm = bluebird.promisifyAll(new PlayMusic()); @@ -89,7 +89,7 @@ function looseMatch(needle, haystack, type) { }); } -export function* search(data, original = {}) { +export function* search(data, original = {}, cleaned = false) { yield pm.initAsync({ email: process.env.GOOGLE_EMAIL, password: process.env.GOOGLE_PASSWORD }) @@ -111,6 +111,9 @@ export function* search(data, original = {}) { const result = yield pm.searchAsync(query, 5); if (!result.entries) { + if (cleaned) { + return { service: 'google' }; + } const matches = album.match(/^[^([]+/); if (matches && matches[0]) { const cleanedData = JSON.parse(JSON.stringify(data)); @@ -120,9 +123,8 @@ export function* search(data, original = {}) { cleanedData.albumName = data.albumName.match(/^[^([]+/)[0].trim(); cleanedData.name = data.name.match(/^[^([]+/)[0].trim(); } - return yield search(cleanedData, data); + return yield search(cleanedData, data, true); } - return { service: 'google' }; } const name = original.name || data.name; diff --git a/routes/search.js b/routes/search.js index e427040..277eb98 100644 --- a/routes/search.js +++ b/routes/search.js @@ -29,9 +29,12 @@ export default function* () { services.forEach((service) => { if (service.id !== share.service) { - const job = queue.create('search', { share, service }).save((err) => { - debug(err || job.id); - }); + const job = queue.create('search', { share, service }) + .attempts(3) + .backoff({ type: 'exponential' }) + .save((err) => { + debug(err || `JobID: ${job.id}`); + }); } }); } diff --git a/routes/share.js b/routes/share.js index c891e4d..4b9441d 100644 --- a/routes/share.js +++ b/routes/share.js @@ -1,10 +1,13 @@ import kue from 'kue'; +import debuglog from 'debug'; import services from '../lib/services'; import render from '../lib/render'; import models from '../models'; import { find, create } from '../lib/share'; +const debug = debuglog('combine.fm:share'); + const queue = kue.createQueue({ redis: process.env.REDIS_URL, }); @@ -33,14 +36,16 @@ export default function* (serviceId, type, itemId, format) { if (!share) { share = yield create(music); - for (const service of services) { - if (service.id === share.service) { - continue; // eslint-disable-line no-continue + services.forEach((service) => { + if (service.id !== share.service) { + const job = queue.create('search', { share, service }) + .attempts(3) + .backoff({ type: 'exponential' }) + .save((err) => { + debug(err || `JobID: ${job.id}`); + }); } - const job = queue.create('search', {share: share, service: service}).save((err) => { - if (!err) console.log(job.id); - }); - } + }); } } diff --git a/worker.js b/worker.js index 2f840b8..53e38f4 100644 --- a/worker.js +++ b/worker.js @@ -17,7 +17,7 @@ const queue = kue.createQueue({ function search(data, done) { const share = data.share; const service = services.find(item => data.service.id === item.id); - debug(`Searching on: ${service}`); + debug(`Searching on: ${service.id}`); co(function* gen() { // eslint-disable-line no-loop-func try { const match = yield service.search(share); @@ -49,10 +49,14 @@ function search(data, done) { } return done(); } catch (err) { + debug(`Error searching on: ${service.id}`); + debug(share); + debug(err); + raven.captureException(err); return done(err); } }).catch((err) => { - debug(`Error searching on: ${service}`); + debug(`Error searching on: ${service.id}`); debug(share); debug(err); raven.captureException(err);