设置服务以在Web集群环境中执行任务

时间:2022-06-20 02:48:52

I am looking for ways to reliably execute a task (just one time at certain date/time) in web clustered environment: for example to send an email reminder to user after 7 days since initial registration. I am aware of ways to accomplish that using cron/django-cron/django-chronograph etc, but everything I found so far seem to be designed for single-server scenario.

我正在寻找在Web集群环境中可靠地执行任务(在特定日期/时间只执行一次)的方法:例如,在初始注册后7天内向用户发送电子邮件提醒。我知道如何使用cron / django-cron / django-chronograph等来实现这一目标,但到目前为止我发现的所有内容似乎都是针对单服务器场景而设计的。

I want to avoid sending duplicate reminders as a result of same job running on multiple servers and so far it seems like rolling up your own database-based solution with locking, expiration timeouts etc in the web cluster is really the only option. Are there any existing solutions for this that would work well in web clustered environment?

我希望避免由于在多个服务器上运行相同的作业而发送重复提醒,并且到目前为止,似乎在Web群集中使用锁定,过期超时等汇总您自己的基于数据库的解决方案实际上是唯一的选择。是否有任何现有的解决方案可以在Web集群环境中很好地工作?

1 个解决方案

#1


1  

You could use Celery Periodic Task.

你可以使用Celery Periodic Task。

from datetime import timedelta

CELERYBEAT_SCHEDULE = {
    'add-every-30-seconds': {
        'task': 'tasks.add',
        'schedule': timedelta(seconds=30),
        'args': (16, 16)
    },
}

CELERY_TIMEZONE = 'UTC'

#1


1  

You could use Celery Periodic Task.

你可以使用Celery Periodic Task。

from datetime import timedelta

CELERYBEAT_SCHEDULE = {
    'add-every-30-seconds': {
        'task': 'tasks.add',
        'schedule': timedelta(seconds=30),
        'args': (16, 16)
    },
}

CELERY_TIMEZONE = 'UTC'