From d7e26ba9d0cd9b2d2c0a19019f9c5f810cfa856d Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Fri, 11 Oct 2019 15:26:24 +0200 Subject: [PATCH] update task messages in case of failure --- inventory_provider/tasks/worker.py | 33 +++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 85e658db..5b867c9d 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -60,9 +60,18 @@ class InventoryTask(Task): )) super().update_state(**kwargs) + def on_failure(self, exc, task_id, args, kwargs, einfo): + self.update_state( + state=states.FAILURE, + meta={ + 'task': task_id, + 'message': str(exc) + }) + super().on_failure(exc, task_id, args, kwargs, einfo) -@app.task -def snmp_refresh_interfaces(hostname, community): + +@app.task(base=InventoryTask, bind=True) +def snmp_refresh_interfaces(self, hostname, community): logger = logging.getLogger(__name__) logger.debug( '>>> snmp_refresh_interfaces(%r, %r)' % (hostname, community)) @@ -76,8 +85,8 @@ def snmp_refresh_interfaces(hostname, community): '<<< snmp_refresh_interfaces(%r, %r)' % (hostname, community)) -@app.task -def netconf_refresh_config(hostname): +@app.task(base=InventoryTask, bind=True) +def netconf_refresh_config(self, hostname): logger = logging.getLogger(__name__) logger.debug('>>> netconf_refresh_config(%r)' % hostname) @@ -90,8 +99,8 @@ def netconf_refresh_config(hostname): logger.debug('<<< netconf_refresh_config(%r)' % hostname) -@app.task -def update_interfaces_to_services(): +@app.task(base=InventoryTask, bind=True) +def update_interfaces_to_services(self): logger = logging.getLogger(__name__) logger.debug('>>> update_interfaces_to_services') @@ -115,8 +124,8 @@ def update_interfaces_to_services(): logger.debug('<<< update_interfaces_to_services') -@app.task -def update_equipment_locations(): +@app.task(base=InventoryTask, bind=True) +def update_equipment_locations(self): logger = logging.getLogger(__name__) logger.debug('>>> update_equipment_locations') @@ -134,8 +143,8 @@ def update_equipment_locations(): logger.debug('<<< update_equipment_locations') -@app.task -def update_circuit_hierarchy(): +@app.task(base=InventoryTask, bind=True) +def update_circuit_hierarchy(self): logger = logging.getLogger(__name__) logger.debug('>>> update_circuit_hierarchy') @@ -165,8 +174,8 @@ def update_circuit_hierarchy(): logger.debug('<<< update_circuit_hierarchy') -@app.task -def update_geant_lambdas(): +@app.task(base=InventoryTask, bind=True) +def update_geant_lambdas(self): logger = logging.getLogger(__name__) logger.debug('>>> update_geant_lambdas') -- GitLab