I'm using Celery in my django project to create tasks to send email at a specific time in the future. User can create a Notification instance with notify_on
datetime field. Then I pass value of notify_on
as a eta
.
class Notification(models.Model):
...
notify_on = models.DateTimeField()
def notification_post_save(instance, *args, **kwargs):
send_notification.apply_async((instance,), eta=instance.notify_on)
signals.post_save.connect(notification_post_save, sender=Notification)
The problem with that approach is that if notify_on
will be changed by the user, he will get two(or more) notifications instead of one.
The question is how do I update the task associated with a specific notification, or somehow delete the old one and create new.