[增强] 启动celery时,发送微信通知
This commit is contained in:
parent
3ba4f23629
commit
57bc55e70d
@ -34,9 +34,11 @@ windows 10
|
||||
|
||||
1) conda activate py37
|
||||
2) 进入项目目录后,例如c:\vnpy2, 运行命令:
|
||||
celery -A vnpy.task.celery_app worker -P eventlet -l debug -f celery.log
|
||||
celery worker -c 2 -A vnpy.task.celery_app -P eventlet -l debug -f celery.log
|
||||
其中:
|
||||
-A 代表运行的模块, worker,表明这是celery的worker,
|
||||
worker,表明这是celery的worker,
|
||||
-c 代表使用多少个cpu作为线程池
|
||||
-A 代表worker运行的模块,
|
||||
-P windows10下使用的协议
|
||||
-l (小写L),表示logging的级别, debug, info 等。
|
||||
-f 代表输出日志文件名
|
||||
@ -60,3 +62,6 @@ windows 10
|
||||
'test_setting': test_setting,
|
||||
'strategy_setting': strategy_setting},
|
||||
task_id=task_id)
|
||||
|
||||
# 清除任务得例子
|
||||
celery -A vnpy.task.celery_app purge
|
||||
|
@ -15,7 +15,6 @@ from celery.utils.log import get_task_logger
|
||||
|
||||
logger = get_task_logger(__name__)
|
||||
|
||||
|
||||
# 添加项目目录
|
||||
vnpy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
|
||||
@ -25,6 +24,7 @@ if vnpy_root not in sys.path:
|
||||
|
||||
# 使用本地配置的
|
||||
from vnpy.trader.utility import load_json
|
||||
|
||||
file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'celery_config.json'))
|
||||
celery_config = load_json(file_path)
|
||||
|
||||
@ -40,6 +40,7 @@ print(u'Celery 使用redis配置:\nbroker:{}\nbackend:{}'.format(broker, backend
|
||||
|
||||
app = Celery('vnpy_task', broker=broker)
|
||||
|
||||
|
||||
# 动态导入task目录下子任务
|
||||
# app.conf.CELERY_IMPORTS = ['vnpy.task.celery_app.worker_started']
|
||||
|
||||
@ -56,12 +57,12 @@ def worker_started():
|
||||
"""发送worker启动的通知"""
|
||||
try:
|
||||
import socket
|
||||
from vnpy.trader.util_logger import setup_logger
|
||||
logger = setup_logger(file_name='celery_worker')
|
||||
logger.inf('celery worker started')
|
||||
from vnpy.trader.util_wechat import send_wx_msg
|
||||
send_wx_msg(u'{} Celery Worker 启动'.format(socket.gethostname()))
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
@app.task(bind=True)
|
||||
def execute(self, func, *args, **kwargs):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user