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

combine all inventory cache tasks to one

parent 748869b6
No related branches found
No related tags found
No related merge requests found
...@@ -48,31 +48,29 @@ def update(): ...@@ -48,31 +48,29 @@ def update():
# return Response("OK") # return Response("OK")
@routes.route("update-interfaces-to-services", methods=['GET']) # @routes.route("update-interfaces-to-services", methods=['GET'])
def update_interfaces_to_services(): # def update_interfaces_to_services():
app.send_task( # app.send_task(
'inventory_provider.tasks.worker.update_interfaces_to_services') # 'inventory_provider.tasks.worker.update_interfaces_to_services')
return Response("OK") # return Response("OK")
#
#
@routes.route("update-service-hierarchy", methods=['GET']) # @routes.route("update-service-hierarchy", methods=['GET'])
def update_service_hierarchy(): # def update_service_hierarchy():
app.send_task('inventory_provider.tasks.worker.update_circuit_hierarchy') # app.send_task('inventory_provider.tasks.worker.update_circuit_hierarchy')
return Response("OK") # return Response("OK")
#
#
@routes.route("update-equipment-locations", methods=['GET']) # @routes.route("update-equipment-locations", methods=['GET'])
def update_equipment_locations(): # def update_equipment_locations():
app.send_task('inventory_provider.tasks.worker.update_equipment_locations') # app.send_task('inventory_provider.tasks.worker.update_equipment_locations')
return Response("OK") # return Response("OK")
@routes.route("update-from-inventory-system", methods=['GET']) @routes.route("update-from-inventory-system", methods=['GET'])
def update_from_inventory_system(): def update_from_inventory_system():
app.send_task( app.send_task(
'inventory_provider.tasks.worker.update_interfaces_to_services') 'inventory_provider.tasks.worker.update_inventory_system_cache')
app.send_task('inventory_provider.tasks.worker.update_circuit_hierarchy')
app.send_task('inventory_provider.tasks.worker.update_equipment_locations')
return Response("OK") return Response("OK")
......
import json import json
import logging import logging
from celery import bootsteps, Task from celery import bootsteps, Task, group
from collections import defaultdict from collections import defaultdict
from lxml import etree from lxml import etree
...@@ -14,8 +16,10 @@ from inventory_provider.db import db, opsdb, alarmsdb ...@@ -14,8 +16,10 @@ from inventory_provider.db import db, opsdb, alarmsdb
from inventory_provider import snmp from inventory_provider import snmp
from inventory_provider import juniper from inventory_provider import juniper
environment.setup_logging() environment.setup_logging()
# TODO: error callback (cf. http://docs.celeryproject.org/en/latest/userguide/calling.html#linking-callbacks-errbacks)
class InventoryTask(Task): class InventoryTask(Task):
...@@ -142,6 +146,9 @@ def netconf_refresh_config(self, hostname): ...@@ -142,6 +146,9 @@ def netconf_refresh_config(self, hostname):
@app.task() @app.task()
def update_interfaces_to_services(): def update_interfaces_to_services():
logger = logging.getLogger(constants.TASK_LOGGER_NAME)
logger.error('HERE: update_interfaces_to_services')
r = get_redis(InventoryTask.config) r = get_redis(InventoryTask.config)
with db.connection(InventoryTask.config["ops-db"]) as cx: with db.connection(InventoryTask.config["ops-db"]) as cx:
services = opsdb.get_circuits(cx) services = opsdb.get_circuits(cx)
...@@ -221,3 +228,17 @@ def update_interface_statuses(): ...@@ -221,3 +228,17 @@ def update_interface_statuses():
service["equipment"], service["equipment"],
service["interface_name"] service["interface_name"]
)) ))
@app.task()
def update_inventory_system_cache():
logger = logging.getLogger(constants.TASK_LOGGER_NAME)
logger.error('HERE: update_inventory_system_cache')
g = group([
update_interfaces_to_services.s(),
update_circuit_hierarchy.s(),
update_equipment_locations.s(),
update_interface_statuses.s()
])
g.apply_async()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment