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

added pending & failure to latch struct

parent 66ae1856
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,9 @@ DB_LATCH_SCHEMA = { ...@@ -13,7 +13,9 @@ DB_LATCH_SCHEMA = {
"properties": { "properties": {
"current": {"type": "integer"}, "current": {"type": "integer"},
"next": {"type": "integer"}, "next": {"type": "integer"},
"this": {"type": "integer"} "this": {"type": "integer"},
"pending": {"type": "boolean"},
"failure": {"type": "boolean"}
}, },
"required": ["current", "next", "this"], "required": ["current", "next", "this"],
"additionalProperties": False "additionalProperties": False
...@@ -35,6 +37,20 @@ def get_latch(r): ...@@ -35,6 +37,20 @@ def get_latch(r):
return latch return latch
def update_latch_status(config, pending=False, failure=False):
logger.debug('updating latch status: pending={}, failure={}'.format(
pending, failure))
for db in config['redis-databases']:
r = _get_redis(config, dbid=db)
latch = get_latch(r)
if not latch:
continue
latch['pending'] = pending
latch['failure'] = failure
r.set('db:latch', json.dumps(latch))
def set_latch(config, new_current, new_next): def set_latch(config, new_current, new_next):
logger.debug('setting latch: new current={}, new next={}'.format( logger.debug('setting latch: new current={}, new next={}'.format(
...@@ -44,7 +60,9 @@ def set_latch(config, new_current, new_next): ...@@ -44,7 +60,9 @@ def set_latch(config, new_current, new_next):
latch = { latch = {
'current': new_current, 'current': new_current,
'next': new_next, 'next': new_next,
'this': db 'this': db,
'pending': False,
'failure': False
} }
r = _get_redis(config, dbid=db) r = _get_redis(config, dbid=db)
......
...@@ -13,7 +13,7 @@ import jsonschema ...@@ -13,7 +13,7 @@ import jsonschema
from inventory_provider.tasks.app import app from inventory_provider.tasks.app import app
from inventory_provider.tasks.common \ from inventory_provider.tasks.common \
import get_next_redis, latch_db, get_latch, set_latch import get_next_redis, latch_db, get_latch, set_latch, update_latch_status
from inventory_provider import config from inventory_provider import config
from inventory_provider import environment from inventory_provider import environment
from inventory_provider.db import db, opsdb from inventory_provider.db import db, opsdb
...@@ -473,6 +473,8 @@ def launch_refresh_cache_all(config): ...@@ -473,6 +473,8 @@ def launch_refresh_cache_all(config):
""" """
_erase_next_db(config) _erase_next_db(config)
update_latch_status(config, pending=True)
# first batch of subtasks: refresh cached opsdb data # first batch of subtasks: refresh cached opsdb data
subtasks = [ subtasks = [
update_junosspace_device_list.apply_async(), update_junosspace_device_list.apply_async(),
...@@ -556,14 +558,22 @@ def refresh_finalizer(self, pending_task_ids_json): ...@@ -556,14 +558,22 @@ def refresh_finalizer(self, pending_task_ids_json):
'message': s 'message': s
}) })
task_ids = json.loads(pending_task_ids_json) try:
logger.debug('task_ids: %r' % task_ids) task_ids = json.loads(pending_task_ids_json)
jsonschema.validate(task_ids, input_schema) logger.debug('task_ids: %r' % task_ids)
_wait_for_tasks(task_ids, update_callback=_update) jsonschema.validate(task_ids, input_schema)
_build_subnet_db(update_callback=_update)
_wait_for_tasks(task_ids, update_callback=_update)
_build_subnet_db(update_callback=_update)
except (jsonschema.ValidationError,
json.JSONDecodeError,
InventoryTaskError) as e:
update_latch_status(InventoryTask.config, failure=True)
raise e
_update('latching current/next dbs')
latch_db(InventoryTask.config) latch_db(InventoryTask.config)
_update('latched current/next dbs')
logger.debug('<<< refresh_finalizer') logger.debug('<<< refresh_finalizer')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment