最新消息:20210917 已从crifan.com换到crifan.org

【已解决】celery beat是什么

celery crifan 3185浏览 0评论

折腾:

【已解决】把Celery+Redis集成到在线Flask中且用supervisor去管理后台服务

期间,看到:

http://yshblog.com/blog/165

提到:

Celery beat

去查查是什么,此处是否需要用

what is Celery beat

Periodic Tasks — Celery 4.1.0 documentation

What is celery beat and how to use it? – Breadcrumbs Collector

what’s difference between celeryd, celery worker, celerybeat? – Stack Overflow

celery.beat — Celery 4.1.0 documentation

好像是周期性任务

后来也看到了,之前的某个项目中,由于用到了periodic的任务:

<code>@celery_app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
    from resources.BackgroundWorker import updateTaskErrandorLocation, BACKGROUND_UPDATE_RUNNING_TASK_ERRANDOR_LOCATION_INTERVAL_SECONDS
    sender.add_periodic_task(BACKGROUND_UPDATE_RUNNING_TASK_ERRANDOR_LOCATION_INTERVAL_SECONDS,
                             updateTaskErrandorLocation.s(), name="update errandor location")

    from resources.BackgroundWorker import updateUserStatus, BACKGROUND_UPDATE_USER_STATUS_INTERVAL_SECONDS
    sender.add_periodic_task(BACKGROUND_UPDATE_USER_STATUS_INTERVAL_SECONDS,
                             updateUserStatus.s(), name="update user status")
</code>

所以其supervisor中也定义了:celery beat

<code>[program:celery-beat]
command=celery beat --app=runningfast.app.celery_app -l info
autostart=true
stdout_logfile=../celery-beat-out.log
stderr_logfile=../celery-beat-err.log
</code>

【总结】

如果你的celery中用到了周期性的任务,则需要加上对应的celery beat,就像心跳一样,作为后台周期任务的服务去运行的。

-》相应的,如果用supervisor去管理celery的任务,则也要同时加上celery beat的program。

转载请注明:在路上 » 【已解决】celery beat是什么

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
93 queries in 0.204 seconds, using 23.37MB memory