相关疑难解决方法(0)

如何动态添加/删除周期性任务到芹菜(celerybeat)

如果我有一个定义如下的函数:

def add(x,y):
  return x+y
Run Code Online (Sandbox Code Playgroud)

有没有办法动态添加这个函数作为芹菜PeriodicTask并在运行时启动它?我希望能够做类似(伪代码)的事情:

some_unique_task_id = celery.beat.schedule_task(add, run_every=crontab(minute="*/30"))
celery.beat.start(some_unique_task_id)
Run Code Online (Sandbox Code Playgroud)

我还想用类似(伪代码)的东西动态地停止或删除该任务:

celery.beat.remove_task(some_unique_task_id)
Run Code Online (Sandbox Code Playgroud)

要么

celery.beat.stop(some_unique_task_id)
Run Code Online (Sandbox Code Playgroud)

仅供参考我没有使用djcelery,它允许您通过django管理员管理定期任务.

python celery celerybeat

43
推荐指数
4
解决办法
2万
查看次数

Django/djcelery 1.8.2 AppRegistryNotReady:无法初始化翻译基础设施

我收到以下错误:

File "/Library/Python/2.7/site-packages/Django-1.8.2-py2.7.egg/django/utils/translation/trans_real.py", line 164, in _add_installed_apps_translations
"The translation infrastructure cannot be initialized before the "
django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
Run Code Online (Sandbox Code Playgroud)

我有一个项目,它不是一个django应用程序,而是一个芹菜应用程序.因此,我还没有创建一个wsgi.pymodels.py或通过创建典型的文件django-admin时,一个项目或应用程序已启动.

我只想使用djcelery能够使用djcelery.schedules.DatabaseScheduler此处指定的类似方法创建周期性任务在运行时添加,修改,删除celery.schedules和此处如何动态添加/删除周期性任务到Celery(celerybeat)

这里给出的问题的解决方案(AppRegistryNotReady,使用uWSGI部署时的转换错误)要求我对vassal.ini文件进行更改.我的实现中没有vassal.ini文件.

我将简要介绍一下我的项目 -

proj
  apps.py
  tasks.py
  celeryconfig.py
  runproj.py
Run Code Online (Sandbox Code Playgroud)
  • apps.py
    from celery import Celery
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'celeryconfig')
    myapp = Celery('myapp')
    myapp.config_from_object('celeryconfig')
    if __name__ == '__main__' …
Run Code Online (Sandbox Code Playgroud)

python django celery celerybeat djcelery

8
推荐指数
1
解决办法
748
查看次数

标签 统计

celery ×2

celerybeat ×2

python ×2

django ×1

djcelery ×1