Commit ce7e4d5f by Owo Sugiana

Web client LinkAja ada opsi --timeout

1 parent 280ee07e
0.3.3 2020-09-07
----------------
- web_client_linkaja.py ada opsi --timeout
0.3.2 2020-08-27 0.3.2 2020-08-27
---------------- ----------------
- Penyesuaian linkaja dimana tahun bisa saja di msg. - Penyesuaian linkaja dimana tahun bisa saja di msg.
......
...@@ -458,6 +458,11 @@ database-nya terlebih dahulu. Lalu buatlah file ``test-agratek.ini``:: ...@@ -458,6 +458,11 @@ database-nya terlebih dahulu. Lalu buatlah file ``test-agratek.ini``::
allowed_ip = allowed_ip =
127.0.0.1 127.0.0.1
10.8.30.1 10.8.30.1
# Notification Message sesuai prefix Invoice ID
notification_message =
3271:PBB Kota Bogor
3676:PBB Kota Tangerang Selatan
3275:PBB Kota Bekasi
[host_bjb] [host_bjb]
ip = 127.0.0.1 ip = 127.0.0.1
......
...@@ -51,6 +51,11 @@ module = iso8583_web.scripts.views.linkaja ...@@ -51,6 +51,11 @@ module = iso8583_web.scripts.views.linkaja
host = bjb host = bjb
timeout = 30 timeout = 30
db_url = postgresql://user:pass@localhost/db db_url = postgresql://user:pass@localhost/db
# Notification Message sesuai prefix Invoice ID
notification_message =
3271:PBB Kota Bogor
3676:PBB Kota Tangerang Selatan
3275:PBB Kota Bekasi
[host_bjb] [host_bjb]
ip = 127.0.0.1 ip = 127.0.0.1
......
...@@ -150,5 +150,6 @@ class View: ...@@ -150,5 +150,6 @@ class View:
def web_job(self, conn, iso): def web_job(self, conn, iso):
conf = self.get_web_conf() conf = self.get_web_conf()
job = WebJob(conn, iso, conf) cls = self.get_web_job_cls()
job = cls(conn, iso, conf)
return job.get_response() return job.get_response()
...@@ -76,7 +76,7 @@ def get_db_session(): ...@@ -76,7 +76,7 @@ def get_db_session():
return conf['db_session'] return conf['db_session']
class Webjob(BaseWebJob): class WebJob(BaseWebJob):
def timeout_error(self): # override def timeout_error(self): # override
return TimeoutError() return TimeoutError()
......
...@@ -27,15 +27,17 @@ default_merchant = 'ldmjakarta1' ...@@ -27,15 +27,17 @@ default_merchant = 'ldmjakarta1'
default_terminal = 'Terminal Name' default_terminal = 'Terminal Name'
default_pwd = 'ldmjkt1pass' default_pwd = 'ldmjkt1pass'
default_msisdn = '628111234567' default_msisdn = '628111234567'
default_timeout = 35
help_url = 'default ' + default_url help_url = 'default ' + default_url
help_count = 'default {}'.format(default_count) help_count = f'default {default_count}'
help_amount = 'wajib saat --payment dan --reversal' help_amount = 'wajib saat --payment dan --reversal'
help_bill_ref = 'wajib saat payment dan reversal, '\ help_bill_ref = 'wajib saat payment dan reversal, '\
'diperoleh dari inquiry response' 'diperoleh dari inquiry response'
help_trx_id = 'Nomor Transaksi Bank, '\ help_trx_id = 'Nomor Transaksi Bank, '\
'opsional saat --payment, wajib saat --reversal' 'opsional saat --payment, wajib saat --reversal'
help_merchant = 'default {}'.format(default_merchant) help_merchant = 'default ' + default_merchant
help_timeout = f'default {default_timeout} detik'
ERRORS = [ ERRORS = [
...@@ -72,15 +74,18 @@ def get_option(argv): ...@@ -72,15 +74,18 @@ def get_option(argv):
parser.add_argument('--pwd', default=default_pwd) parser.add_argument('--pwd', default=default_pwd)
parser.add_argument('--msisdn', default=default_msisdn) parser.add_argument('--msisdn', default=default_msisdn)
parser.add_argument('--msg', default='') parser.add_argument('--msg', default='')
parser.add_argument(
'--timeout', help=help_timeout, default=default_timeout, type=int)
return parser.parse_args(argv) return parser.parse_args(argv)
def send(thread_id, p): def send(thread_id, p):
url = server_info['url'] url = server_info['url']
timeout = server_info['timeout']
log_info('Request: {}'.format(p)) log_info('Request: {}'.format(p))
start = time() start = time()
try: try:
resp = requests.post(url, data=p, headers=headers, timeout=10) resp = requests.post(url, data=p, headers=headers, timeout=timeout)
durations[thread_id] = time() - start durations[thread_id] = time() - start
data = p['trx_type'] == '021' and InquiryResponse() or \ data = p['trx_type'] == '021' and InquiryResponse() or \
PaymentResponse() PaymentResponse()
...@@ -162,6 +167,7 @@ class App: ...@@ -162,6 +167,7 @@ class App:
def __init__(self, argv): def __init__(self, argv):
self.option = get_option(argv) self.option = get_option(argv)
server_info['url'] = self.option.url server_info['url'] = self.option.url
server_info['timeout'] = self.option.timeout
def create_thread(self, thread_id, data): def create_thread(self, thread_id, data):
thread = Thread(target=send, args=[thread_id, data]) thread = Thread(target=send, args=[thread_id, data])
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!