mirror of
https://github.com/veops/cmdb.git
synced 2025-08-09 15:04:52 +08:00
Realize /api/v0.1/ci_relations/s [done]
This commit is contained in:
@@ -9,9 +9,11 @@ from flask import current_app
|
||||
import api.lib.cmdb.ci
|
||||
from api.extensions import celery
|
||||
from api.extensions import db
|
||||
from api.extensions import rd
|
||||
from api.extensions import es
|
||||
from api.extensions import rd
|
||||
from api.lib.cmdb.const import CMDB_QUEUE
|
||||
from api.lib.cmdb.const import REDIS_PREFIX_CI
|
||||
from api.lib.cmdb.const import REDIS_PREFIX_CI_RELATION
|
||||
|
||||
|
||||
@celery.task(name="cmdb.ci_cache", queue=CMDB_QUEUE)
|
||||
@@ -24,10 +26,9 @@ def ci_cache(ci_id):
|
||||
if current_app.config.get("USE_ES"):
|
||||
es.update(ci_id, ci)
|
||||
else:
|
||||
rd.delete(ci_id)
|
||||
rd.add({ci_id: json.dumps(ci)})
|
||||
rd.create_or_update({ci_id: json.dumps(ci)}, REDIS_PREFIX_CI)
|
||||
|
||||
current_app.logger.info("%d flush.........." % ci_id)
|
||||
current_app.logger.info("{0} flush..........".format(ci_id))
|
||||
|
||||
|
||||
@celery.task(name="cmdb.ci_delete", queue=CMDB_QUEUE)
|
||||
@@ -37,6 +38,29 @@ def ci_delete(ci_id):
|
||||
if current_app.config.get("USE_ES"):
|
||||
es.delete(ci_id)
|
||||
else:
|
||||
rd.delete(ci_id)
|
||||
rd.delete(ci_id, REDIS_PREFIX_CI)
|
||||
|
||||
current_app.logger.info("%d delete.........." % ci_id)
|
||||
current_app.logger.info("{0} delete..........".format(ci_id))
|
||||
|
||||
|
||||
@celery.task(name="cmdb.ci_relation_cache", queue=CMDB_QUEUE)
|
||||
def ci_relation_cache(parent_id, child_id):
|
||||
children = rd.get([parent_id], REDIS_PREFIX_CI_RELATION)[0]
|
||||
children = json.loads(children) if children is not None else []
|
||||
children.append(child_id)
|
||||
|
||||
rd.create_or_update({parent_id: json.dumps(list(set(children)))}, REDIS_PREFIX_CI_RELATION)
|
||||
|
||||
current_app.logger.info("ADD ci relation cache: {0} -> {1}".format(parent_id, child_id))
|
||||
|
||||
|
||||
@celery.task(name="cmdb.ci_relation_delete", queue=CMDB_QUEUE)
|
||||
def ci_relation_delete(parent_id, child_id):
|
||||
children = rd.get([parent_id], REDIS_PREFIX_CI_RELATION)[0]
|
||||
children = json.loads(children) if children is not None else []
|
||||
if child_id in children:
|
||||
children.remove(child_id)
|
||||
|
||||
rd.create_or_update({parent_id: json.dumps(list(set(children)))}, REDIS_PREFIX_CI_RELATION)
|
||||
|
||||
current_app.logger.info("DELETE ci relation cache: {0} -> {1}".format(parent_id, child_id))
|
||||
|
Reference in New Issue
Block a user