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

Finished feature DBOARD3-486-update-start-time-in-version.

parents 480a23ce 781a4620
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,8 @@ VERSION_SCHEMA = {
'this': {'type': 'integer'},
'failure': {'type': 'boolean'},
'pending': {'type': 'boolean'},
'timestamp': {'type': 'number'}
'timestamp': {'type': 'number'},
'update-started': {'type': 'number'}
},
'required': ['current', 'next', 'this', 'pending', 'failure'],
'additionalProperties': False
......
......@@ -21,7 +21,8 @@ DB_LATCH_SCHEMA = {
'this': {'type': 'integer'},
'pending': {'type': 'boolean'},
'failure': {'type': 'boolean'},
'timestamp': {'type': 'number'}
'timestamp': {'type': 'number'},
'update-started': {'type': 'number'}
},
'required': ['current', 'next', 'this'],
'additionalProperties': False
......@@ -101,22 +102,27 @@ def update_latch_status(config, pending=False, failure=False):
f'updating latch for db {db} with pending=True, '
f'but latch is already {latch}')
latch['timestamp'] = now
if not latch['pending'] and pending:
# we are starting a new update
latch['update-started'] = now
latch['pending'] = pending
latch['failure'] = failure
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(
new_current, new_next))
for db in config['redis-databases']:
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 = {
'current': new_current,
......@@ -124,7 +130,8 @@ def set_single_latch(r, db, new_current, new_next, timestamp):
'this': db,
'pending': False,
'failure': False,
'timestamp': timestamp
'timestamp': timestamp,
'update-started': update_timestamp
}
r.set('db:latch', json.dumps(latch))
......@@ -148,7 +155,8 @@ def latch_db(config):
config,
new_current=latch['next'],
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):
......
......@@ -466,7 +466,8 @@ def _erase_next_db(config):
saved_latch['this'],
saved_latch['current'],
saved_latch['next'],
saved_latch.get('timestamp', 0)
saved_latch.get('timestamp', 0),
saved_latch.get('update-started', 0)
)
rp.execute()
......@@ -475,7 +476,8 @@ def _erase_next_db(config):
config,
new_current=saved_latch['current'],
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
......
......@@ -32,7 +32,7 @@ def test_next_redis(data_config, mocked_redis):
:param mocked_redis:
: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)
assert r
......@@ -41,6 +41,7 @@ def test_next_redis(data_config, mocked_redis):
assert latch['current'] == 10
assert latch['next'] == 20
assert latch['timestamp'] == 100
assert latch['update-started'] == 123
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