Skip to content
Snippets Groups Projects
Commit 424ed7c2 authored by Erik Reid's avatar Erik Reid
Browse files

added 'update-started' to latch

parent 480a23ce
Branches
Tags
No related merge requests found
...@@ -20,7 +20,8 @@ VERSION_SCHEMA = { ...@@ -20,7 +20,8 @@ VERSION_SCHEMA = {
'this': {'type': 'integer'}, 'this': {'type': 'integer'},
'failure': {'type': 'boolean'}, 'failure': {'type': 'boolean'},
'pending': {'type': 'boolean'}, 'pending': {'type': 'boolean'},
'timestamp': {'type': 'number'} 'timestamp': {'type': 'number'},
'update-started': {'type': 'number'}
}, },
'required': ['current', 'next', 'this', 'pending', 'failure'], 'required': ['current', 'next', 'this', 'pending', 'failure'],
'additionalProperties': False 'additionalProperties': False
......
...@@ -21,7 +21,8 @@ DB_LATCH_SCHEMA = { ...@@ -21,7 +21,8 @@ DB_LATCH_SCHEMA = {
'this': {'type': 'integer'}, 'this': {'type': 'integer'},
'pending': {'type': 'boolean'}, 'pending': {'type': 'boolean'},
'failure': {'type': 'boolean'}, 'failure': {'type': 'boolean'},
'timestamp': {'type': 'number'} 'timestamp': {'type': 'number'},
'update-started': {'type': 'number'}
}, },
'required': ['current', 'next', 'this'], 'required': ['current', 'next', 'this'],
'additionalProperties': False 'additionalProperties': False
...@@ -101,22 +102,26 @@ def update_latch_status(config, pending=False, failure=False): ...@@ -101,22 +102,26 @@ def update_latch_status(config, pending=False, failure=False):
f'updating latch for db {db} with pending=True, ' f'updating latch for db {db} with pending=True, '
f'but latch is already {latch}') f'but latch is already {latch}')
latch['timestamp'] = now latch['timestamp'] = now
if not latch['pending'] and pending:
# we are starting a new update
latch['update-started'] = now
latch['pending'] = pending latch['pending'] = pending
latch['failure'] = failure latch['failure'] = failure
r.set('db:latch', json.dumps(latch)) r.set('db:latch', json.dumps(latch))
def set_latch(config, new_current, new_next, timestamp): def set_latch(config, new_current, new_next, timestamp, update_timestamp):
logger.debug('setting latch: new current={}, new next={}'.format( logger.debug('setting latch: new current={}, new next={}'.format(
new_current, new_next)) new_current, new_next))
for db in config['redis-databases']: for db in config['redis-databases']:
r = _get_redis(config, dbid=db) r = _get_redis(config, dbid=db)
set_single_latch(r, db, new_current, new_next, timestamp) set_single_latch(
r, db, new_current, new_next, timestamp, update_timestamp)
def set_single_latch(r, db, new_current, new_next, timestamp): def set_single_latch(r, db, new_current, new_next, timestamp, update_timestamp):
latch = { latch = {
'current': new_current, 'current': new_current,
...@@ -124,7 +129,8 @@ def set_single_latch(r, db, new_current, new_next, timestamp): ...@@ -124,7 +129,8 @@ def set_single_latch(r, db, new_current, new_next, timestamp):
'this': db, 'this': db,
'pending': False, 'pending': False,
'failure': False, 'failure': False,
'timestamp': timestamp 'timestamp': timestamp,
'update-started': update_timestamp
} }
r.set('db:latch', json.dumps(latch)) r.set('db:latch', json.dumps(latch))
...@@ -148,7 +154,8 @@ def latch_db(config): ...@@ -148,7 +154,8 @@ def latch_db(config):
config, config,
new_current=latch['next'], new_current=latch['next'],
new_next=db_ids[next_idx], new_next=db_ids[next_idx],
timestamp=time.time()) timestamp=time.time(),
update_timestamp=latch.get('update-started', 0))
def _get_redis(config, dbid=None): def _get_redis(config, dbid=None):
......
...@@ -466,7 +466,8 @@ def _erase_next_db(config): ...@@ -466,7 +466,8 @@ def _erase_next_db(config):
saved_latch['this'], saved_latch['this'],
saved_latch['current'], saved_latch['current'],
saved_latch['next'], saved_latch['next'],
saved_latch.get('timestamp', 0) saved_latch.get('timestamp', 0),
saved_latch.get('update-started', 0)
) )
rp.execute() rp.execute()
...@@ -475,7 +476,8 @@ def _erase_next_db(config): ...@@ -475,7 +476,8 @@ def _erase_next_db(config):
config, config,
new_current=saved_latch['current'], new_current=saved_latch['current'],
new_next=saved_latch['next'], new_next=saved_latch['next'],
timestamp=saved_latch.get('timestamp', 0)) timestamp=saved_latch.get('timestamp', 0),
update_timestamp=saved_latch.get('update-started', 0))
@log_task_entry_and_exit @log_task_entry_and_exit
......
...@@ -32,7 +32,7 @@ def test_next_redis(data_config, mocked_redis): ...@@ -32,7 +32,7 @@ def test_next_redis(data_config, mocked_redis):
:param mocked_redis: :param mocked_redis:
:return: :return:
""" """
common.set_latch(data_config, 10, 20, 100) common.set_latch(data_config, 10, 20, 100, 123)
r = common.get_next_redis(data_config) r = common.get_next_redis(data_config)
assert r assert r
...@@ -41,6 +41,7 @@ def test_next_redis(data_config, mocked_redis): ...@@ -41,6 +41,7 @@ def test_next_redis(data_config, mocked_redis):
assert latch['current'] == 10 assert latch['current'] == 10
assert latch['next'] == 20 assert latch['next'] == 20
assert latch['timestamp'] == 100 assert latch['timestamp'] == 100
assert latch['update-started'] == 123
def test_next_redis_with_none(data_config, mocked_redis): def test_next_redis_with_none(data_config, mocked_redis):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment