From 763d8a7f2f66a4c8fa0fbc46704e4fbc61d7816a Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Fri, 13 Aug 2021 10:03:15 +0000 Subject: [PATCH] added set_single_latch ready for update task transaction. RE. DBOARD3-433 --- inventory_provider/tasks/common.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/inventory_provider/tasks/common.py b/inventory_provider/tasks/common.py index ad929ed4..9cfa8437 100644 --- a/inventory_provider/tasks/common.py +++ b/inventory_provider/tasks/common.py @@ -98,7 +98,7 @@ def update_latch_status(config, pending=False, failure=False): if not pending and not failure: if not latch['pending'] and not latch['failure']: logger.error( - 'updating latch for db {db} with pending=failure=True, ' + f'updating latch for db {db} with pending=True, ' f'but latch is already {latch}') latch['timestamp'] = now latch['pending'] = pending @@ -112,17 +112,21 @@ def set_latch(config, new_current, new_next, timestamp): new_current, new_next)) for db in config['redis-databases']: - latch = { - 'current': new_current, - 'next': new_next, - 'this': db, - 'pending': False, - 'failure': False, - 'timestamp': timestamp - } - r = _get_redis(config, dbid=db) - r.set('db:latch', json.dumps(latch)) + set_single_latch(r, db, new_current, new_next, timestamp) + + +def set_single_latch(r, db, new_current, new_next, timestamp): + + latch = { + 'current': new_current, + 'next': new_next, + 'this': db, + 'pending': False, + 'failure': False, + 'timestamp': timestamp + } + r.set('db:latch', json.dumps(latch)) def latch_db(config): -- GitLab