celerybeat 自动禁用周期性任务

发布于 2024-11-10 04:31:05 字数 2163 浏览 0 评论 0原文

我想使用 django-celery 的管理界面为 celery 创建一个定期任务。我设置了一个任务,当手动或通过脚本调用时,该任务运行得很好。它只是无法通过 celerybeat 工作。根据调试日志,任务在第一次检索时设置为 enabled = False,我想知道为什么。

添加定期任务并将 [1, False] 作为位置参数传递时,该任务将自动禁用,并且我看不到任何进一步的输出。当不带参数添加时,任务会被执行,但会立即引发异常,因为我没有提供所需的参数(有道理)。

有人看出这里有什么问题吗?

提前致谢。

这是提供参数后的输出:

[DEBUG/Beat] SELECT "djcelery_periodictask"."id", [...] 
             FROM "djcelery_periodictask" 
             WHERE "djcelery_periodictask"."enabled" = true ; args=(True,)

[DEBUG/Beat] SELECT "djcelery_intervalschedule"."id", [...] 
             FROM "djcelery_intervalschedule" 
             WHERE "djcelery_intervalschedule"."id" = 3 ; args=(3,)

[DEBUG/Beat] SELECT (1) AS "a" 
             FROM "djcelery_periodictask" 
             WHERE "djcelery_periodictask"."id" = 3  LIMIT 1; args=(3,)

[DEBUG/Beat] UPDATE "djcelery_periodictask" 
             SET "name" = E'<taskname>', "task" = E'<task.module.path>', 
                 "interval_id" = 3, "crontab_id" = NULL, 
                 "args" = E'[1, False,]', "kwargs" = E'{}', "queue" = NULL, 
                 "exchange" = NULL, "routing_key" = NULL, 
                 "expires" = NULL, "enabled" = false, 
                 "last_run_at" = E'2011-05-25 00:45:23.242387', "total_run_count" = 9, 
                 "date_changed" = E'2011-05-25 09:28:06.201148' 
             WHERE "djcelery_periodictask"."id" = 3; 
             args=(
                   u'<periodic-task-name>', u'<task.module.path>', 
                   3, u'[1, False,]', u'{}', 
                   False, u'2011-05-25 00:45:23.242387', 9, 
                   u'2011-05-25 09:28:06.201148', 3
             )

[DEBUG/Beat] Current schedule:
<ModelEntry: celery.backend_cleanup celery.backend_cleanup(*[], **{}) {<crontab: 0 4 * (m/h/d)>}
[DEBUG/Beat] Celerybeat: Waking up in 5.00 seconds.

编辑: 它适用于以下设置。我仍然不知道为什么它不能与 django-celery 一起使用。

CELERYBEAT_SCHEDULE = {
    "example": {
        "task": "<task.module.path>",
        "schedule": crontab(),
        "args": (1, False)
    },
}

I'd like to create a periodic task for celery using django-celery's admin interface. I have a task set up which runs great when called manually or by script. It just doesn't work through celerybeat. According to the debug logs the task is set to enabled = False on first retrieval and I wonder why.

When adding the periodic task and passing [1, False] as positional arguments, the task is automatically disabled and I don't see any further output. When added without arguments the task is executed but raises an exception instantly because I didn't supply the needed arguments (makes sense).

Does anyone see what's the problem here?

Thanks in advance.

This is the output after supplying arguments:

[DEBUG/Beat] SELECT "djcelery_periodictask"."id", [...] 
             FROM "djcelery_periodictask" 
             WHERE "djcelery_periodictask"."enabled" = true ; args=(True,)

[DEBUG/Beat] SELECT "djcelery_intervalschedule"."id", [...] 
             FROM "djcelery_intervalschedule" 
             WHERE "djcelery_intervalschedule"."id" = 3 ; args=(3,)

[DEBUG/Beat] SELECT (1) AS "a" 
             FROM "djcelery_periodictask" 
             WHERE "djcelery_periodictask"."id" = 3  LIMIT 1; args=(3,)

[DEBUG/Beat] UPDATE "djcelery_periodictask" 
             SET "name" = E'<taskname>', "task" = E'<task.module.path>', 
                 "interval_id" = 3, "crontab_id" = NULL, 
                 "args" = E'[1, False,]', "kwargs" = E'{}', "queue" = NULL, 
                 "exchange" = NULL, "routing_key" = NULL, 
                 "expires" = NULL, "enabled" = false, 
                 "last_run_at" = E'2011-05-25 00:45:23.242387', "total_run_count" = 9, 
                 "date_changed" = E'2011-05-25 09:28:06.201148' 
             WHERE "djcelery_periodictask"."id" = 3; 
             args=(
                   u'<periodic-task-name>', u'<task.module.path>', 
                   3, u'[1, False,]', u'{}', 
                   False, u'2011-05-25 00:45:23.242387', 9, 
                   u'2011-05-25 09:28:06.201148', 3
             )

[DEBUG/Beat] Current schedule:
<ModelEntry: celery.backend_cleanup celery.backend_cleanup(*[], **{}) {<crontab: 0 4 * (m/h/d)>}
[DEBUG/Beat] Celerybeat: Waking up in 5.00 seconds.

EDIT:
It works with the following setting. I still have no idea why it doesn't work with django-celery.

CELERYBEAT_SCHEDULE = {
    "example": {
        "task": "<task.module.path>",
        "schedule": crontab(),
        "args": (1, False)
    },
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热情消退 2024-11-17 04:31:05

我有同样的问题。确保参数采用 JSON 格式。例如,尝试将位置参数设置为 [1, false]——小写“false”——我刚刚在 django-celery 实例(版本 2.2.4)上测试了它并且它有效。

对于关键字参数,请使用类似 {"name": "aldarund"}

I had the same issue. Make sure the arguments are JSON formatted. For example, try setting the positional args to [1, false] -- lowercase 'false' -- I just tested it on a django-celery instance (version 2.2.4) and it worked.

For the keyword args, use something like {"name": "aldarund"}

廻憶裏菂餘溫 2024-11-17 04:31:05

我也遇到了同样的问题。

随着 djcelery 中周期性任务模型的描述(“JSON 编码的位置参数”),与 Evan 的答案相同。我尝试在保存之前使用 python json lib 进行编码。

这与我一起使用

import json 
o = PeriodicTask()
o.kwargs = json.dumps({'myargs': 'hello'})
o.save()

celery 版本 3.0.11

I got the same problem too.

With the description of PeriodicTask models in djcelery ("JSON encoded positional arguments"), same as Evan answer. I try using python json lib to encode before save.

And this work with me

import json 
o = PeriodicTask()
o.kwargs = json.dumps({'myargs': 'hello'})
o.save()

celery version 3.0.11

风吹雨成花 2024-11-17 04:31:05
CELERYBEAT_SCHEDULE = {
    "example": {
        "task": "<task.module.path>",
        "schedule": crontab(),
        "enable": False
    },
}

我尝试过并且成功了。我在 celerybeat v5.1.2 上运行

CELERYBEAT_SCHEDULE = {
    "example": {
        "task": "<task.module.path>",
        "schedule": crontab(),
        "enable": False
    },
}

I tried and it worked.I run on celery beat v5.1.2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文