From e7f5d2a50dc9c561a293c20181937338346e968b Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <adhisimon@gmail.com> Date: Mon, 31 May 2021 17:12:17 +0700 Subject: [PATCH] active sending --- lib/core-callback/sender.js | 12 ++++++++++++ lib/matrix.js | 2 ++ 2 files changed, 14 insertions(+) diff --git a/lib/core-callback/sender.js b/lib/core-callback/sender.js index 8483648..b965e52 100644 --- a/lib/core-callback/sender.js +++ b/lib/core-callback/sender.js @@ -101,6 +101,12 @@ const sender = async (data, xid, retry) => { }); matrix.callback_sender.sent += 1; + matrix.callback_sender.active_count += 1; + matrix.callback_sender.active_sending[xid] = { + ts: new Date(), + trxId: data.trx_id, + reverseUrl: data.reverse_url, + }; if (isPostpaid) { matrix.callback_sender.sent_using_post += 1; @@ -121,6 +127,7 @@ const sender = async (data, xid, retry) => { ts: new Date(), eCode: e.code, eMessage: e.message, + trxId: data.trx_id, reverseUrl: data.reverse_url, httpStatus: e.response && e.response.status, responseBody: e.response && e.response.data, @@ -145,6 +152,11 @@ const sender = async (data, xid, retry) => { }); sender(data, xid, (retry || 0) + 1); } + } finally { + matrix.callback_sender.active_count -= 1; + if (matrix.callback_sender.active_sending[xid]) { + delete matrix.callback_sender.active_sending[xid]; + } } }; diff --git a/lib/matrix.js b/lib/matrix.js index d27e86d..243702d 100644 --- a/lib/matrix.js +++ b/lib/matrix.js @@ -24,5 +24,7 @@ module.exports = { sent_using_get: 0, sent_using_post: 0, last_error: null, + active_count: 0, + active_sending: {}, }, }; -- 1.9.0