Skip to content

Instantly share code, notes, and snippets.

@joaorafaelm
Created April 23, 2021 15:37
Show Gist options
  • Save joaorafaelm/45c45d39a58b303aec8e2567c516caaf to your computer and use it in GitHub Desktop.
Save joaorafaelm/45c45d39a58b303aec8e2567c516caaf to your computer and use it in GitHub Desktop.
one off periodic task using django celery beat
from django_celery_beat.models import PeriodicTask, ClockedSchedule
from django.utils.timezone import localtime, timedelta
import json
now = localtime()
clocked, _ = ClockedSchedule.objects.get_or_create(
clocked_time=now + timedelta(days=10)
)
PeriodicTask.objects.create(
clocked=clocked,
name="Example Periodic Task",
task="hyke.tasks.send_reminder",
one_off=True,
args=json.dumps({
"member_id": 123,
"template_name": "BK Training Call"
}),
expires=now + timedelta(hours=1)
)
@Alimo-ras
Copy link

hi, thank this file really helped me,
i did some testing and i didnt get the values for args, the task function just get the keys,
i manage to make it work by changing args to kwargs or passing a tuple for args in json format
just want to mention this for any suggestion or helping any one seeing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment