Skip to content

Commit 9b7b725

Browse files
committed
add timeout code for redoer
1 parent 9c2b0fa commit 9b7b725

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ Similar to the consumer, the redoer is also a continually-running process.
202202
docker compose run --env AWS_PROFILE=localstack --env LOG_LEVEL=DEBUG redoer
203203
```
204204

205-
`LOG_LEVEL` is optional; defaults to `INFO`.
205+
Environment variables:
206+
207+
- `LOG_LEVEL` is optional; defaults to `INFO`.
208+
- `SZ_CALL_TIMEOUT_SECONDS`
209+
- Optional; defaults to 420 seconds (7 min.)
210+
- Sets the maximum amount of time the Exporter will wait for a Senzing
211+
`process_redo_record` to complete before bailing and moving on.
206212

207213
### Exporter
208214

middleware/consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def clean_up(signum, frm):
187187
start_alarm_timer(SZ_CALL_TIMEOUT_SECONDS)
188188
resp = sz_eng.add_record(rcd['DATA_SOURCE'], rcd['RECORD_ID'], body)
189189
cancel_alarm_timer()
190-
log.info(SZ_TAG + 'Successful add_record having ReceiptHandle: '
190+
log.debug(SZ_TAG + 'Successful add_record having ReceiptHandle: '
191191
+ receipt_handle)
192192
except sz.SzUnknownDataSourceError as sz_uds_err:
193193
try:

middleware/redoer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from loglib import *
99
log = retrieve_logger()
1010

11+
from timeout_handling import *
12+
1113
try:
1214
log.info('Importing senzing_core library . . .')
1315
import senzing_core as sz_core
@@ -17,6 +19,7 @@
1719
log.error(e)
1820
sys.exit(1)
1921

22+
SZ_CALL_TIMEOUT_SECONDS = int(os.environ.get('SZ_CALL_TIMEOUT_SECONDS', 420))
2023
SZ_CONFIG = json.loads(os.environ['SENZING_ENGINE_CONFIGURATION_JSON'])
2124

2225
# How long to wait before attempting next Senzing op.
@@ -62,7 +65,9 @@ def go():
6265

6366
if have_rcd:
6467
try:
68+
start_alarm_timer(SZ_CALL_TIMEOUT_SECONDS)
6569
sz_eng.process_redo_record(rcd)
70+
cancel_alarm_timer()
6671
have_rcd = 0
6772
log.debug(SZ_TAG + 'Successfully redid one record via process_redo_record().')
6873
continue
@@ -77,6 +82,12 @@ def go():
7782
+ ' for this record; dropping on the floor and moving on.')
7883
time.sleep(WAIT_SECONDS)
7984
continue
85+
except LongRunningCallTimeoutEx as lrex:
86+
# Abandon and move on.
87+
have_rcd = 0
88+
log.error(f'{SZ_TAG} {type(lrex).__module__}.{type(lrex).__qualname__} :: '
89+
+ f'Long-running Senzing add_record call exceeded {SZ_CALL_TIMEOUT_SECONDS} sec.; '
90+
+ f'skipping and moving on; receipt_handle was: {receipt_handle}')
8091
except sz.SzError as sz_err:
8192
log.error(SZ_TAG + str(sz_err))
8293
sys.exit(1)

0 commit comments

Comments
 (0)