How to programmatically generate celerybeat entries with celery and Django

≯℡__Kan透↙ 提交于 2019-12-02 18:31:15

This is what ended up working for me :

def addTask(request):

  intervalSchedule = IntervalSchedule.from_schedule(schedule(timedelta(seconds=10)))
  intervalSchedule.save()

  modelData = dict(
      name="dcTestPersist",
      task="technologytrackerapi.tasks.createRecord",
      interval_id=intervalSchedule.pk,
  )

  periodicTask = PeriodicTask(**modelData)
  periodicTask.save()

  me = ModelEntry(periodicTask)

  try:
      me.save()

  except:
    from django.db import connection
    print connection.queries
    raise

  return render_to_response('taskView.html')

I had to wrap the Periodic Task in a ModelEntry.

I think what you want to do is add PeriodicTasks to the database. Looks like the bottom section of https://github.com/ask/django-celery/blob/master/djcelery/admin.py is how they add in tasks in the admin -- you'll need to offer something similar on the front end.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!