from views.api import json_api from models.base import r, LISTENER_TASK_KEY from app import app as sse_api from ext import db, sse from models.messaging import Message, Notification def restart_listener(sender): task_id = r.get(LISTENER_TASK_KEY) if task_id: revoke(task_id) task_id = app.send_task('wechat.tasks.listener') r.set(LISTENER_TASK_KEY, task_id) stopped.connect(restart_listener) from libs.listener import bot @app.task def listener(): with json_api.app_context(): bot.join() @app.task def async_retrieve_data(): with json_api.app_context(): _retrieve_data()
from views.api import json_api from models.redis import db as r, LISTENER_TASK_KEY from app import app as sse_api from ext import db, sse from models.messaging import Message, Notification def restart_listener(sender): task_id = r.get(LISTENER_TASK_KEY) if task_id: revoke(task_id) task_id = app.send_task('wechat.tasks.listener') r.set(LISTENER_TASK_KEY, task_id) stopped.connect(restart_listener) from libs.listener import bot @app.task def listener(): with json_api.app_context(): bot.join() @app.task def async_retrieve_data(): with json_api.app_context(): _retrieve_data()