Reputation: 957
I want to create delayed task and if there would be some conditions, I need to find that task and revoke it.
This is how I create task:
notify_before_departure.apply_async(
args=(user.fcm_registration_token, booking.bus_stop_from.title,),
eta=notification_time,
)
So is there any attribute apply_async
has where I can define my custom ID which can later be used to revoke this exact task? Something like this:
# create task
notify_before_departure.apply_async(
args=(user.fcm_registration_token, booking.bus_stop_from.title,),
eta=notification_time,
custom_id=booking.id
)
# revoke if needed
from celery.task.control import revoke
revoke(booking.id, terminate=True)
Upvotes: 5
Views: 2684
Reputation: 957
Well, answering my own question after reading FAQ :
notify_before_departure.apply_async(
args=(user.fcm_registration_token, booking.bus_stop_from.title,),
eta=notification_time,
task_id=f"departure_push_for_booking_{booking.id}"
)
And then:
revoke(f"departure_push_for_booking_{booking.id}", terminate=True)
Upvotes: 8