I am trying to run a periodic task with django celery, and it is dynamically added by users using custom arguments. I have the following code to start the task. I only want it to run once as it takes a while for it to set up, and I have an infinite while loop that constantly checks for changes on a website.
schedule, created = IntervalSchedule.objects.get_or_create(every=100,period=IntervalSchedule.DAYS,)
PeriodicTask.objects.create(interval=schedule, enabled=True, name=name,task='scanner.tasks.texting', args=json.dumps([phone_number, carrier_address]),)
The problem is that when I create the task, it is not started and needs to wait for the interval before starting. Is it possible to start the tasks when the object is created?
Otherwise, I could change the interval to just a second to start immediately. The problem with this implementation is that it will start the thread every second, even though I just want to run it once, and let it keep running in the background.
Does anyone have a solution to this?