I have created an advertising app in my websilte with django and the Ad model looks like this
AdModel(models.Model):
starting_date = models.DateField()
expiring_date = models.DateField()
active = models.BooleanField(default=False)
My goal is to create a task using Celery to activate (set ad.active = True) and deactivate ads based on their starting and expiring date and since the celery beat is for periodic recurring task so it's not going to solve it.
Probably passing the starting_date as eta to the task like this will be the solution:
#signals.py
@receiver(post_save, sender=AdModel)
def start_task(sender, instance, created, **kwargs):
if created:
ad_activator_task.apply_async( (instance.id), eta=instance.starting_date)
If the instance.starting_date is three months far from now, is it going to be executed ? i have read that Celery not usefull for long term future tasks (far future) and i'm kinda confused.
note: im using Redis as broker
active
field anyway? You can simply calculate if it is active by looking at thestarting_date
andexpiring_date
. – Willem Van Onsem