Skip to content

Commit

Permalink
catch the consumer failures and fail the main process accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasochem committed Aug 23, 2023
1 parent 7fd0e7b commit 940e9db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/pay/payment_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/util/process_life_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 940e9db

Please sign in to comment.