Created
April 23, 2021 15:37
-
-
Save joaorafaelm/45c45d39a58b303aec8e2567c516caaf to your computer and use it in GitHub Desktop.
one off periodic task using django celery beat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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