Commit 0bb34ba5295259d386333652fcd83ced9fd4e84c

Authored by Adhidarma Hadiwinoto
1 parent c2a3ea41fd
Exists in master

random result timeout

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

1 "use strict"; 1 "use strict";
2 2
3 const moment = require('moment'); 3 const moment = require('moment');
4 4
5 const pull = require('./pull'); 5 const pull = require('./pull');
6 const logger = require('./logger').get(); 6 const logger = require('./logger').get();
7 7
8 var config; 8 var config;
9 var matrix; 9 var matrix;
10 10
11 function init(options) { 11 function init(options) {
12 config = options.config; 12 config = options.config;
13 matrix = options.matrix; 13 matrix = options.matrix;
14 } 14 }
15 15
16 function _buy(task) { 16 function _buy(task) {
17 let destination = Number(task.destination); 17 let destination = Number(task.destination);
18 if (destination % 2) { 18 if (destination % 2) {
19 let msg = 'Isi ' + task.remote_product + ' ke ' + task.destination + ' gagal karena nomor tujuan ganjil'; 19 let msg = 'Isi ' + task.remote_product + ' ke ' + task.destination + ' gagal karena nomor tujuan ganjil';
20 pull.report(task.trx_id, '14', msg); 20 pull.report(task.trx_id, '14', msg);
21 } else { 21 } else {
22 let sn = moment().format('YYYYMMDDHHmmssSSS') 22 let sn = moment().format('YYYYMMDDHHmmssSSS')
23 let msg = 'Isi ' + task.remote_product + ' ke ' + task.destination + ' berhasil karena nomor tujuan genap dengan SN=' + sn; 23 let msg = 'Isi ' + task.remote_product + ' ke ' + task.destination + ' berhasil karena nomor tujuan genap dengan SN=' + sn;
24 pull.report(task.trx_id, '00', msg, sn); 24 pull.report(task.trx_id, '00', msg, sn);
25 } 25 }
26 } 26 }
27 27
28 function buy(_task) { 28 function buy(_task) {
29 let task = JSON.parse(JSON.stringify(_task)); 29 let task = JSON.parse(JSON.stringify(_task));
30 30
31 logger.verbose('Buy on partner', {task: task}); 31 logger.verbose('Buy on partner', {task: task});
32 setTimeout( 32 setTimeout(
33 function() { 33 function() {
34 _buy(task); 34 _buy(task);
35 }, 35 },
36 2000 36 (config.max_result_timeout_ms || 2000) * Math.random()
37 ) 37 )
38 } 38 }
39 39
40 exports.init = init; 40 exports.init = init;
41 exports.buy = buy; 41 exports.buy = buy;
42 42