Commit d8459894213d0f50f59c66d15c12e80d6cbeb07a
1 parent
00f7a96595
Exists in
master
advice based on taskHistory
Showing 1 changed file with 35 additions and 7 deletions Side-by-side Diff
aaa.js
... | ... | @@ -11,6 +11,7 @@ var moment = require('moment'); |
11 | 11 | var naturalSort = require('javascript-natural-sort'); |
12 | 12 | var pkginfo = require('pkginfo')(module, 'version'); |
13 | 13 | |
14 | +var taskHistory = require('./task-history'); | |
14 | 15 | var AntiSameDayDupe = require('./anti-same-day-dupe-oo'); |
15 | 16 | var antiSameDayDupe; |
16 | 17 | |
... | ... | @@ -250,7 +251,10 @@ function pull() { |
250 | 251 | |
251 | 252 | logger.info('New task', {task: task}); |
252 | 253 | |
253 | - if (Number(config.globals.no_same_day_dupe)) { | |
254 | + if (partner.topupAdvice) { | |
255 | + doRequestOrAdvice(task); | |
256 | + } | |
257 | + else if (Number(config.globals.no_same_day_dupe)) { | |
254 | 258 | checkForSameDayDuplicate(task, partner.topupRequest); |
255 | 259 | } else { |
256 | 260 | partner.topupRequest(task); |
... | ... | @@ -290,15 +294,35 @@ function checkForSameDayDuplicate(task, cb) { |
290 | 294 | }, |
291 | 295 | function() { |
292 | 296 | // dupe with same request id |
297 | + cb(task); | |
298 | + } | |
299 | + ); | |
300 | +} | |
293 | 301 | |
294 | - if (partner.topupAdvice) { | |
295 | - partner.topupAdvice(task); | |
296 | - } else { | |
297 | - cb(task); | |
298 | - } | |
302 | +function doRequestOrAdvice(task) { | |
303 | + | |
304 | + if (!partner.topupAdvice) { | |
305 | + partner.topupRequest(task); | |
306 | + return; | |
307 | + } | |
299 | 308 | |
309 | + taskHistory.get(task, function(err, archivedTask) { | |
310 | + if (err) { | |
311 | + logger.warn('Error finding task on history, doing topupRequest as fallback', {task: task, err: err}); | |
312 | + partner.topupRequest(task); | |
313 | + return; | |
300 | 314 | } |
301 | - ); | |
315 | + | |
316 | + if (archivedTask) { | |
317 | + logger.verbose('Found task on history, flowing to topupAdvice', {task: task}); | |
318 | + partner.topupAdvice(task); | |
319 | + } | |
320 | + else { | |
321 | + taskHistory.put(task); | |
322 | + logger.verbose('Task not found on history, flowing to topupRequest', {task: task}); | |
323 | + partner.topupRequest(task); | |
324 | + } | |
325 | + }) | |
302 | 326 | } |
303 | 327 | |
304 | 328 | function publishTaskToRedis(task) { |
... | ... | @@ -674,6 +698,10 @@ function start(_config, _partner, options) { |
674 | 698 | createRedisClient(); |
675 | 699 | initMongoClient(); |
676 | 700 | |
701 | + if (partner.topupAdvice) { | |
702 | + taskHistory.init(options); | |
703 | + } | |
704 | + | |
677 | 705 | setTimeout(pullLoop, 10 * 1000); |
678 | 706 | } |
679 | 707 |