Commit 49aa80909ffc329da3f91a5fc7e80514ac291bed

Authored by Adhidarma Hadiwinoto
1 parent 7ec4016657
Exists in master

perbaikan retry

Showing 1 changed file with 15 additions and 18 deletions Side-by-side Diff

... ... @@ -6,7 +6,7 @@ var xml = require("xml2js").parseString;
6 6 var config;
7 7 var callbackReport;
8 8  
9   -var max_retry = 3;
  9 +var max_retry = 15;
10 10 var sleep_before_retry = 3000;
11 11  
12 12 process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
... ... @@ -80,16 +80,7 @@ function topupRequest(task, retry) {
80 80 console.log('HTTP Request Error (' + task['requestId'] + '): ');
81 81 console.log(err);
82 82  
83   - if (retry) {
84   -
85   - console.log('Retrying trx hit (' + retry + ')');
86   - setTimeout(function() {
87   - topupRequest(task, retry - 1);
88   - }, sleep_before_retry);
89   -
90   - } else {
91   - callbackReport(task['requestId'], '40', 'Gangguan koneksi ke suplier');
92   - }
  83 + callbackReport(task['requestId'], '40', 'Gangguan koneksi ke suplier');
93 84 return;
94 85 }
95 86  
... ... @@ -126,6 +117,18 @@ function topupRequest(task, retry) {
126 117  
127 118 var message = result.respon.pesan[0].replace(/\n/g, ' ');
128 119  
  120 + if (response_code == '54' || response_code == '68') {
  121 + if (retry) {
  122 + setTimeout(function() {
  123 + topupRequest(task, retry - 1);
  124 + }, 60000);
  125 +
  126 + } else {
  127 + callbackReport(task['requestId'], '68', message);
  128 + }
  129 + return;
  130 + }
  131 +
129 132  
130 133 if (response_code == '00') {
131 134  
... ... @@ -141,13 +144,7 @@ function topupRequest(task, retry) {
141 144 }
142 145  
143 146 callbackReport(task['requestId'], response_code, message);
144   -
145   - if (response_code == '54' || response_code == '68') {
146   - setTimeout(function() {
147   - topupRequest(task, 5);
148   - }, 60000);
149   - }
150   -
  147 +
151 148 });
152 149 });
153 150 }