예제 #1
0
파일: notice.py 프로젝트: kooksee/kservices
async def notify_start_handle():
    from utils.app import Application
    app = Application.current()

    async def _f():
        f = await _notify_start_handle()
        print(f)

    app.timers["notice"] = run_async(_f())
예제 #2
0
파일: notice.py 프로젝트: kooksee/kservices
def notify_stop_handle():
    from utils.app import Application
    app = Application.current()

    try:
        notice = app.timers["notice"]
        del app.timers["notice"]
        notice.cancel()
    except Exception as e:
        print(e)
예제 #3
0
def init_url():

    from utils.app import Application
    app = Application.current()

    from kservices.handlers import notice_add, notify_start, notify_stop, ok
    app.route("/api/notice", methods=["POST"])(notice_add)
    app.route("/api/notify", methods=["POST"])(notify_start)
    app.route("/api/notify", methods=["DELETE"])(notify_stop)
    app.route("/service/status", methods=["GET"])(ok)
    app.route("/", methods=["GET"])(ok)
예제 #4
0
async def __log_post(data):
    """
    data:{
        "cnt": "内容: text",
        "name": "服务名字: text"
    }

    :param data:
    :return:
    """

    name = data.get("name", "test")
    cnt = data.get("cnt", {})

    from utils.app import Application
    app = Application.current()

    st, col = app.mongo.col(name)
    result = await col.insert_one(cnt)
    print('result %s' % repr(result.inserted_id))
예제 #5
0
파일: notice.py 프로젝트: kooksee/kservices
async def _notify_start_handle():
    from utils.app import Application
    app = Application.current()

    r = app.redis

    st, data = await r.execute("rpop", "notice")
    if not st:
        print(data)
        return

    if not data:
        return

    data = json.loads(data)
    msgtype = data.get("msgtype")
    if msgtype == 'notice':
        dingding_post(dingding_msg(data.get("notice")))
    elif msgtype == 'log':
        from bussiness.log import log_post
        log_post(data.get("log"))
    else:
        print(data)
예제 #6
0
async def ok(req):
    """
    检测服务以及外部接口
    :param req:
    :return:
    """
    app = Application.current()

    r = app.redis

    try:
        st, res = await r.execute('config_get')
        if st:
            redis_status = "ok"
            print("redis config:\n", res)
        else:
            print("redis exception\n", res)
            redis_status = res
    except Exception as e:
        redis_status = str(e)
        print(e)

    return rep({"redis_status": redis_status, "timers": app.timers.keys()})
예제 #7
0
파일: config.py 프로젝트: kooksee/kservices
def init_config():
    from utils.app import Application
    app = Application.current()

    if not hasattr(app, "timers"):
        app.timers = {}

    import os
    from kservices.const import Env

    _e = os.environ.get("app_env", Env.local)
    if _e == Env.local:
        _f = LocalConfig()
    elif _e == Env.dev:
        _f = DevConfig()
    elif _e == Env.uat:
        _f = UatConfig()
    elif _e == Env.production:
        _f = ProConfig()
    else:
        _f = LocalConfig()

    app.config.from_object(_f)
    app.debug = _f.DEBUG
예제 #8
0
def init_rabbitmq():
    from utils.app import Application
    app = Application.current()
    app.redis = RabbitMQManager(config=app.config.get("REDIS"))
예제 #9
0
def init_mongodb():
    from utils.app import Application
    app = Application.current()
    app.mongo = MongoManager(app.config.get("MONGODB_DB"),
                             uri=app.config.get("MONGODB_URI"))