Commit c79d437bb96c173cbcd5e8ca8e64b16dbd35154b
1 parent
d2d9093e7f
Exists in
master
Ubah delay after core error dari skipNext menjadi sleep
Showing 2 changed files with 32 additions and 11 deletions Side-by-side Diff
index.js
1 | 1 | const DEFAULT_CORE_REQUEST_TIMEOUT = 5 * 1000; |
2 | +const DEFAULT_SLEEP_AFTER_CORE_ERROR_MS = 3000; | |
2 | 3 | const MAX_REPORT_RETRY = 30; |
3 | 4 | const REPORT_RETRY_SLEEP_MS = 2000; |
4 | 5 | |
... | ... | @@ -8,10 +9,12 @@ const config = require('komodo-sdk/config'); |
8 | 9 | const coreUrl = require('komodo-sdk/core-url'); |
9 | 10 | const logger = require('komodo-sdk/logger'); |
10 | 11 | |
12 | +const sleep = require('./lib/sleep'); | |
13 | + | |
11 | 14 | let partner; |
12 | 15 | let first = true; |
13 | 16 | let coreIsHealthy = null; |
14 | -let skipNext = 0; | |
17 | +// let skipNext = 0; | |
15 | 18 | |
16 | 19 | const DEFAULT_CORE_AXIOS_CONFIG = { |
17 | 20 | headers: { 'Content-Type': 'application/json' }, |
... | ... | @@ -34,12 +37,12 @@ function detectCoreStatusChange(isHealthy, url, err) { |
34 | 37 | } |
35 | 38 | |
36 | 39 | async function getTask() { |
37 | - if (!partner) return; | |
40 | + if (!partner) return null; | |
38 | 41 | |
39 | - if (skipNext > 0) { | |
40 | - skipNext -= 1; | |
41 | - return; | |
42 | - } | |
42 | + // if (skipNext > 0) { | |
43 | + // skipNext -= 1; | |
44 | + // return null; | |
45 | + // } | |
43 | 46 | |
44 | 47 | if (first) { |
45 | 48 | first = false; |
... | ... | @@ -65,11 +68,12 @@ async function getTask() { |
65 | 68 | detectCoreStatusChange(true, coreEndpoint); |
66 | 69 | task = result.data.task; |
67 | 70 | } catch (e) { |
68 | - skipNext = 3; | |
71 | + // skipNext = 3; | |
69 | 72 | detectCoreStatusChange(false, coreEndpoint, e); |
73 | + await sleep(DEFAULT_SLEEP_AFTER_CORE_ERROR_MS); | |
70 | 74 | } |
71 | 75 | |
72 | - if (!task) return; | |
76 | + if (!task) return null; | |
73 | 77 | |
74 | 78 | task.remote_product = ((config.remote_products || {})[task.product]) || task.product; |
75 | 79 | |
... | ... | @@ -77,10 +81,15 @@ async function getTask() { |
77 | 81 | |
78 | 82 | if (task.inquiry_only) { |
79 | 83 | if (typeof partner.inquiry === 'function') partner.inquiry(task); |
80 | - return; | |
84 | + return task; | |
85 | + } | |
86 | + | |
87 | + if (typeof partner.pay === 'function') { | |
88 | + partner.pay(task); | |
89 | + return task; | |
81 | 90 | } |
82 | 91 | |
83 | - if (typeof partner.pay === 'function') partner.pay(task); | |
92 | + return null; | |
84 | 93 | } |
85 | 94 | |
86 | 95 | const getTaskLooper = async () => { |
... | ... | @@ -88,7 +97,7 @@ const getTaskLooper = async () => { |
88 | 97 | |
89 | 98 | setTimeout(() => { |
90 | 99 | getTaskLooper(); |
91 | - }, config,postpaid_pull_interval_ms || config.pull_interval_ms || 1000); | |
100 | + }, config.postpaid_pull_interval_ms || config.pull_interval_ms || 1000); | |
92 | 101 | }; |
93 | 102 | |
94 | 103 | exports.setPartner = (val) => { |