Django Celery 定时任务无输出
Django Celery scheduled task no output
我正在使用 Django 并希望某个任务每天 运行ned 两次(09:00 和 17:00)。
于是在网上找到了Celery,看起来还不错。我按照一些教程进行了设置。
我在数据库中设置了一个周期性任务,每分钟 运行s(用于测试)。或者,它没有,它只是这么说的:
[2020-12-15 14:32:34,997: INFO/MainProcess] Scheduler: Sending due task ResumePentest (VulnManager.tasks.resumePentest)
[2020-12-15 14:32:34,998: DEBUG/MainProcess] VulnManager.tasks.resumePentest sent. id->277c73a8-58bc-41ea-b2ba-4aa7af0c8b94
我不认为它实际上 运行s,因为我尝试了一些不同的“调试”选项:创建文件、打印文本、运行 我的实际命令。 None 其中似乎有效。
我的 tasks.py 文件看起来像这样(用于测试):
from __future__ import absolute_import, unicode_literals
from celery import shared_task
@shared_task
def resumePentest():
f = open("/home/marvin/demofile2.txt", "a")
f.write("Now the file has more content!")
f.close()
我 运行 使用此命令的芹菜工人:
celery -A VulnScanner beat -l DEBUG --scheduler django_celery_beat.schedulers:DatabaseScheduler
有什么提示吗?不确定我做错了什么?如果需要更多信息,请告诉我。
celery worker的全部输出:
celery beat v5.0.4 (singularity) is starting.
__ - ... __ - _
LocalTime -> 2020-12-15 14:44:26
Configuration ->
. broker -> amqp://guest:**@localhost:5672//
. loader -> celery.loaders.app.AppLoader
. scheduler -> django_celery_beat.schedulers.DatabaseScheduler
. logfile -> [stderr]@%DEBUG
. maxinterval -> 5.00 seconds (5s)
[2020-12-15 14:44:26,388: DEBUG/MainProcess] Setting default socket timeout to 30
[2020-12-15 14:44:26,389: INFO/MainProcess] beat: Starting...
[2020-12-15 14:44:26,389: DEBUG/MainProcess] DatabaseScheduler: initial read
[2020-12-15 14:44:26,389: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:26,390: DEBUG/MainProcess] DatabaseScheduler: Fetching database schedule
[2020-12-15 14:44:26,392: DEBUG/MainProcess] Using selector: EpollSelector
[2020-12-15 14:44:26,396: DEBUG/MainProcess] Current schedule:
<ModelEntry: ResumePentest VulnManager.tasks.resumePentest(*[], **{}) <freq: 1.00 minute>>
<ModelEntry: celery.backend_cleanup celery.backend_cleanup(*[], **{}) <crontab: 0 4
* *
* (m/h/d/dM/MY), UTC>
>
[2020-12-15 14:44:26,429: DEBUG/MainProcess] beat: Ticking with max interval->5.00 seconds
[2020-12-15 14:44:26,448: DEBUG/MainProcess] Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@ubuntuserver', 'copyright': 'Copyright (c) 2007-2019 Pivotal Software, Inc.', 'information': 'Licensed under the MPL 1.1. Website: https://rabbitmq.com', 'platform': 'Erlang/OTP 22.2.7', 'product': 'RabbitMQ', 'version': '3.8.2'}, mechanisms: [b'PLAIN', b'AMQPLAIN'], locales: ['en_US']
[2020-12-15 14:44:26,449: INFO/MainProcess] Scheduler: Sending due task ResumePentest (VulnManager.tasks.resumePentest)
[2020-12-15 14:44:26,455: DEBUG/MainProcess] using channel_id: 1
[2020-12-15 14:44:26,457: DEBUG/MainProcess] Channel open
[2020-12-15 14:44:26,459: DEBUG/MainProcess] beat: Synchronizing schedule...
[2020-12-15 14:44:26,459: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:26,467: DEBUG/MainProcess] VulnManager.tasks.resumePentest sent. id->d33fe09b-2e25-4f7b-aec9-03ea4a630ab9
[2020-12-15 14:44:26,469: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2020-12-15 14:44:31,477: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
^C[2020-12-15 14:44:33,765: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:33,766: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:33,766: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:33,766: DEBUG/MainProcess] Writing entries...
使用它的最终目标是使用 greenbone / gvm-cli 开始(在 9:00)和停止(在 17:00)安全扫描。
尝试使用此命令检查新任务:celery -A proj worker -l INFO
。
有关可用命令行选项的完整列表,请使用帮助命令:celery help
我正在使用 Django 并希望某个任务每天 运行ned 两次(09:00 和 17:00)。 于是在网上找到了Celery,看起来还不错。我按照一些教程进行了设置。
我在数据库中设置了一个周期性任务,每分钟 运行s(用于测试)。或者,它没有,它只是这么说的:
[2020-12-15 14:32:34,997: INFO/MainProcess] Scheduler: Sending due task ResumePentest (VulnManager.tasks.resumePentest)
[2020-12-15 14:32:34,998: DEBUG/MainProcess] VulnManager.tasks.resumePentest sent. id->277c73a8-58bc-41ea-b2ba-4aa7af0c8b94
我不认为它实际上 运行s,因为我尝试了一些不同的“调试”选项:创建文件、打印文本、运行 我的实际命令。 None 其中似乎有效。
我的 tasks.py 文件看起来像这样(用于测试):
from __future__ import absolute_import, unicode_literals
from celery import shared_task
@shared_task
def resumePentest():
f = open("/home/marvin/demofile2.txt", "a")
f.write("Now the file has more content!")
f.close()
我 运行 使用此命令的芹菜工人:
celery -A VulnScanner beat -l DEBUG --scheduler django_celery_beat.schedulers:DatabaseScheduler
有什么提示吗?不确定我做错了什么?如果需要更多信息,请告诉我。
celery worker的全部输出:
celery beat v5.0.4 (singularity) is starting.
__ - ... __ - _
LocalTime -> 2020-12-15 14:44:26
Configuration ->
. broker -> amqp://guest:**@localhost:5672//
. loader -> celery.loaders.app.AppLoader
. scheduler -> django_celery_beat.schedulers.DatabaseScheduler
. logfile -> [stderr]@%DEBUG
. maxinterval -> 5.00 seconds (5s)
[2020-12-15 14:44:26,388: DEBUG/MainProcess] Setting default socket timeout to 30
[2020-12-15 14:44:26,389: INFO/MainProcess] beat: Starting...
[2020-12-15 14:44:26,389: DEBUG/MainProcess] DatabaseScheduler: initial read
[2020-12-15 14:44:26,389: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:26,390: DEBUG/MainProcess] DatabaseScheduler: Fetching database schedule
[2020-12-15 14:44:26,392: DEBUG/MainProcess] Using selector: EpollSelector
[2020-12-15 14:44:26,396: DEBUG/MainProcess] Current schedule:
<ModelEntry: ResumePentest VulnManager.tasks.resumePentest(*[], **{}) <freq: 1.00 minute>>
<ModelEntry: celery.backend_cleanup celery.backend_cleanup(*[], **{}) <crontab: 0 4
* *
* (m/h/d/dM/MY), UTC>
>
[2020-12-15 14:44:26,429: DEBUG/MainProcess] beat: Ticking with max interval->5.00 seconds
[2020-12-15 14:44:26,448: DEBUG/MainProcess] Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@ubuntuserver', 'copyright': 'Copyright (c) 2007-2019 Pivotal Software, Inc.', 'information': 'Licensed under the MPL 1.1. Website: https://rabbitmq.com', 'platform': 'Erlang/OTP 22.2.7', 'product': 'RabbitMQ', 'version': '3.8.2'}, mechanisms: [b'PLAIN', b'AMQPLAIN'], locales: ['en_US']
[2020-12-15 14:44:26,449: INFO/MainProcess] Scheduler: Sending due task ResumePentest (VulnManager.tasks.resumePentest)
[2020-12-15 14:44:26,455: DEBUG/MainProcess] using channel_id: 1
[2020-12-15 14:44:26,457: DEBUG/MainProcess] Channel open
[2020-12-15 14:44:26,459: DEBUG/MainProcess] beat: Synchronizing schedule...
[2020-12-15 14:44:26,459: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:26,467: DEBUG/MainProcess] VulnManager.tasks.resumePentest sent. id->d33fe09b-2e25-4f7b-aec9-03ea4a630ab9
[2020-12-15 14:44:26,469: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2020-12-15 14:44:31,477: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
^C[2020-12-15 14:44:33,765: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:33,766: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:33,766: DEBUG/MainProcess] Writing entries...
[2020-12-15 14:44:33,766: DEBUG/MainProcess] Writing entries...
使用它的最终目标是使用 greenbone / gvm-cli 开始(在 9:00)和停止(在 17:00)安全扫描。
尝试使用此命令检查新任务:celery -A proj worker -l INFO
。
有关可用命令行选项的完整列表,请使用帮助命令:celery help