【问题标题】:How start background periodic task with django-background-tasks如何使用 django-background-tasks 启动后台定期任务
【发布时间】:2020-01-10 05:11:22
【问题描述】:

我想为我的SQLite 文件中的检查值创建定期任务。我尝试使用 django-background-tasks 创建重复任务,但它不起作用。当我在 cmd 中使用 python manage.py process_tasks 时,它工作正常。如何使用 start django 启动此任务而不使用此命令?

我在 Windows 10 上开发我的网络应用程序。

urls.py

from django.contrib import admin
from django.urls import path, include
from client import tasks as task

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('client.urls')),
    path('account/', include('account.urls')),
]

task.check_groups(repeat=10, repeat_until=None)

tasks.py

from background_task import background
from django.utils import timezone
from client.models import StudyGroup, Account

@background()
def check_groups():
    check_active_groups()
    check_inactive_groups()

【问题讨论】:

    标签: python django


    【解决方案1】:

    来自文档:

    设置一个 cron 任务(或长时间运行的进程)来执行任务

    您必须设置 cron 或其他一些定期运行程序来调用该命令,因为 Django 本身无法执行此操作。

    【讨论】:

      猜你喜欢
      • 2015-08-29
      • 2019-06-03
      • 2019-01-16
      • 2019-07-07
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2022-08-10
      • 1970-01-01
      相关资源
      最近更新 更多