mirror of
https://github.com/veops/cmdb.git
synced 2025-08-08 07:52:42 +08:00
first commit to github
This commit is contained in:
1
cmdb-api/tasks/__init__.py
Normal file
1
cmdb-api/tasks/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# -*- coding:utf-8 -*-
|
30
cmdb-api/tasks/cmdb.py
Normal file
30
cmdb-api/tasks/cmdb.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from extensions import celery
|
||||
from extensions import db
|
||||
from lib.utils import rd
|
||||
import lib.ci
|
||||
|
||||
|
||||
@celery.task(name="cmdb.ci_cache", queue="cmdb_async")
|
||||
def ci_cache(ci_id):
|
||||
time.sleep(0.1)
|
||||
db.session.close()
|
||||
m = lib.ci.CIManager()
|
||||
ci = m.get_ci_by_id(ci_id, need_children=False, use_master=True)
|
||||
rd.delete(ci_id)
|
||||
rd.add({ci_id: json.dumps(ci)})
|
||||
current_app.logger.info("%d caching.........." % ci_id)
|
||||
|
||||
|
||||
@celery.task(name="cmdb.ci_delete", queue="cmdb_async")
|
||||
def ci_delete(ci_id):
|
||||
current_app.logger.info(ci_id)
|
||||
rd.delete(ci_id)
|
||||
current_app.logger.info("%d delete.........." % ci_id)
|
21
cmdb-api/tasks/statis.py
Normal file
21
cmdb-api/tasks/statis.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
|
||||
import datetime
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from extensions import celery
|
||||
from extensions import db
|
||||
from models.statis import UrlRecord
|
||||
|
||||
|
||||
@celery.task(name="statis.url_record", queue="statis_async")
|
||||
def url_record(url, method, remote_addr, response_time, status_code, source):
|
||||
current_app.logger.info("%s add 1" % url)
|
||||
now = datetime.datetime.now()
|
||||
u = UrlRecord(url=url, response_time=response_time, is_ok=1,
|
||||
source="default", hits=1, method=method, created_at=now,
|
||||
remote_addr=remote_addr)
|
||||
db.session.add(u)
|
||||
db.session.commit()
|
Reference in New Issue
Block a user