Commit 24e876dacc8529ef43fae19713075b85df65fc72
1 parent
387132d838
Exists in
master
pull: putTaskToMatrix and updateTaskOnMatrix
Showing 1 changed file with 40 additions and 2 deletions Side-by-side Diff
gateway/pull.js
... | ... | @@ -16,6 +16,14 @@ if (config.handler_name) { |
16 | 16 | process.title = "KOMODO-GW@" + config.handler_name; |
17 | 17 | } |
18 | 18 | |
19 | +if (!matrix.pending_tasks) { | |
20 | + matrix.sdk_pending_tasks = []; | |
21 | +} | |
22 | + | |
23 | +if (!matrix.active_tasks) { | |
24 | + matrix.sdk_unresponsed_tasks = []; | |
25 | +} | |
26 | + | |
19 | 27 | heartbeat.setModuleType('gateway'); |
20 | 28 | |
21 | 29 | var partner; |
... | ... | @@ -80,6 +88,32 @@ function pullTask() { |
80 | 88 | }); |
81 | 89 | } |
82 | 90 | |
91 | +function putTaskToMatrix(task) { | |
92 | + if (matrix.sdk_unresponsed_tasks.indexOf(task.trx_id) < 0) { | |
93 | + matrix.sdk_unresponsed_tasks.push(task.trix_id); | |
94 | + } | |
95 | + | |
96 | + if (matrix.sdk_pending_tasks.indexOf(task.trx_id) < 0) { | |
97 | + matrix.sdk_pending_tasks.push(task.trx_id); | |
98 | + } | |
99 | +} | |
100 | + | |
101 | +function updateTaskOnMatrix(trx_id, rc) { | |
102 | + const unresponsed_task_idx = matrix.sdk_unresponsed_tasks.indexOf(trx_id); | |
103 | + if (unresponsed_task_idx >= 0) { | |
104 | + matrix.sdk_unresponsed_tasks.splice(unresponsed_task_idx, 1); | |
105 | + } | |
106 | + | |
107 | + if (rc !== '68') { | |
108 | + return; | |
109 | + } | |
110 | + | |
111 | + const pending_task_idx = matrix.sdk_pending_tasks.indexOf(trx_id); | |
112 | + if (pending_task_idx >= 0) { | |
113 | + matrix.sdk_pending_tasks.splice(pending_task_idx, 1); | |
114 | + } | |
115 | +} | |
116 | + | |
83 | 117 | function forwardCoreTaskToPartner(coreMessage) { |
84 | 118 | let task; |
85 | 119 | |
... | ... | @@ -94,6 +128,8 @@ function forwardCoreTaskToPartner(coreMessage) { |
94 | 128 | |
95 | 129 | task.remote_product = getRemoteProduct(task.product); |
96 | 130 | |
131 | + putTaskToMatrix(task); | |
132 | + | |
97 | 133 | taskArchive.get(task, function(res) { |
98 | 134 | if (res && partner.advice) { |
99 | 135 | partner.advice(task); |
... | ... | @@ -102,8 +138,6 @@ function forwardCoreTaskToPartner(coreMessage) { |
102 | 138 | partner.buy(task); |
103 | 139 | } |
104 | 140 | }); |
105 | - | |
106 | - | |
107 | 141 | } |
108 | 142 | |
109 | 143 | function replaceRc(original_rc) { |
... | ... | @@ -118,6 +152,10 @@ function report(data) { |
118 | 152 | |
119 | 153 | let core_pull_report_url; |
120 | 154 | |
155 | + if (data && data.trx_id && data.rc) { | |
156 | + updateTaskOnMatrix(data.trx_id, data.rc); | |
157 | + } | |
158 | + | |
121 | 159 | if (config.core_url) { |
122 | 160 | core_pull_report_url = config.core_url + '/pull/report'; |
123 | 161 | } else if (config.pull_url.report) { |