From 940e9db8d70fa32bdaa61f9cd1db71b5d4bbef43 Mon Sep 17 00:00:00 2001 From: Nicolas Ochem Date: Wed, 23 Aug 2023 15:08:03 -0700 Subject: [PATCH] catch the consumer failures and fail the main process accordingly --- src/pay/payment_producer.py | 10 ++++++++-- src/util/process_life_cycle.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pay/payment_producer.py b/src/pay/payment_producer.py index 1afe0c21..6a957d7f 100644 --- a/src/pay/payment_producer.py +++ b/src/pay/payment_producer.py @@ -111,6 +111,7 @@ def __init__( self.payments_queue = payments_queue self.life_cycle = life_cycle self.dry_run = dry_run + self.consumer_failure = False self.payment_calc = PhasedPaymentCalculator( self.founders_map, @@ -148,8 +149,12 @@ def exit(self, exit_code): self.life_cycle.is_running() and threading.current_thread() is not threading.main_thread() ): - os.kill(os.getpid(), signal.SIGUSR1) - logger.debug("Sending sigusr1 signal.") + if self.consumer_failure: + os.kill(os.getpid(), signal.SIGUSR2) + logger.debug("Payment failure, sending sigusr2 signal to main thread.") + else: + os.kill(os.getpid(), signal.SIGUSR1) + logger.debug("Sending sigusr1 signal.") exit_program( exit_code, "TRD Exit triggered by producer", @@ -676,4 +681,5 @@ def on_success(self, pymnt_batch): self.notify_retry_fail_thread() def on_fail(self, pymnt_batch): + self.consumer_failure = True pass diff --git a/src/util/process_life_cycle.py b/src/util/process_life_cycle.py index c15ae095..85ee686f 100644 --- a/src/util/process_life_cycle.py +++ b/src/util/process_life_cycle.py @@ -2,7 +2,7 @@ import logging import queue import signal -from _signal import SIGABRT, SIGILL, SIGSEGV, SIGTERM, SIGUSR1 +from _signal import SIGABRT, SIGILL, SIGSEGV, SIGTERM, SIGUSR1, SIGUSR2 from enum import Enum, auto from time import sleep @@ -301,7 +301,7 @@ def do_set_up_dirs(self, e): self.__baking_dirs = BakingDirs(self.args, self.__cfg.get_baking_address()) def do_register_signals(self, e): - for sig in (SIGABRT, SIGILL, SIGSEGV, SIGTERM): + for sig in (SIGABRT, SIGILL, SIGSEGV, SIGTERM, SIGUSR2): signal.signal(sig, self.stop_handler) signal.signal(SIGUSR1, self.producer_exit_handler)