如何更改Celery Beat Service的默认路径?

Moo*_*oon 8 python celery

我安装Celery为Windows服务。我的代码动作* .pid和芹菜日志文件到另一个目录,但三个文件(celerybeat-schedule.bakcelerybeat-schedule.dircelerybeat-schedule.dat)这我不能动弹。

我使用以下代码更改其他文件的默认路径:

command = '"{celery_path}" -A {proj_dir} beat -f "{log_path}" -l info --pidfile="{pid_path}" '.format(
celery_path=os.path.join(PYTHONSCRIPTPATH, 'celery.exe'),
proj_dir=PROJECTDIR,
# log_path_1=os.path.join(INSTDIR,'celery_2.log')),
log_path=os.path.join(tmpdir,'celery_'+cur_date_time+'.log'),
pid_path = os.path.join(tmpdir,'celerybeat_'+cur_date_time+'.pid'))
Run Code Online (Sandbox Code Playgroud)

如何更改Celery Beat Service的默认路径?

Dej*_*kic 5

如果您执行celery -A your.project.app beat --help它,它会为您打印非常有用的 CLI 帮助,您可以在其中找到问题的解决方案 --s <path to the scheduler database file>标志。

-s SCHEDULE, --schedule SCHEDULE
                      Path to the schedule database. Defaults to celerybeat-
                      schedule. The extension '.db' may be appended to the
                      filename. Default is celerybeat-schedule.
Run Code Online (Sandbox Code Playgroud)

您所要做的就是将计划数据库文件的完整路径传递给您的 Celery beat 进程。例子:-s C:/services/celery/celerybeat-schedule.db


Moo*_*oon 5

最后,我可以使用以下代码更改芹菜服务的路径。

command = '"{celery_path}" -A {proj_dir} beat -f "{log_path}" -l info --pidfile="{pid_path}" '.format(
            celery_path=os.path.join(PYTHONSCRIPTPATH, 'celery.exe'),
            proj_dir=PROJECTDIR,
            # log_path_1=os.path.join(INSTDIR,'celery_2.log')),
            log_path=os.path.join(CELERYDIR,'celery_'+cur_date_time+'.log'),
            # bak_path=os.path.join(CELERYDIR,'celerybeat-schedule'),
            pid_path = os.path.join(CELERYDIR,'celerybeat_'+cur_date_time+'.pid'))
Run Code Online (Sandbox Code Playgroud)