My task is:
Suppose one activity has to be started at specific time. The person who started activity will change the activity status from Open to In progress. I've to check the activity status and if the status is still Not started at that time, then I've to send mails periodically for every 15 or 20 minutes.
Code I try to execute for every 15 sec from a specific time using apply_async(eta)
I triggered this periodic task in signals (when ever activity created or updated) used apply_async(args, kwargs ,eta). I'm sending activity instance(Activity Object having all activity details including status) in kwargs to the task above I mentioned.
If I update the activity status then only for one time the task is taking the args, kwargs from the signal
In second beat task is taking args, kwargs from the CELERYBEAT_SCHEDULE settings (My periodic task should not use these args and kwargs)
issue is: celery task is taking args, kwargs from the CELERYBEAT_SCHEDULE settings in the second beat.
Pls help someone
Below is the code for your reference
1.celery beat settings
2.my signals triggers celery task upon Activity model updation
3.celery task
CELERYBEAT_SCHEDULE = {
'periodic_send_email': {
'task': 'cloud_app.tasks.periodic_send_email',
'schedule': timedelta(seconds=15),
'args': (16, 16)
},
}
@receiver(signals.post_save, sender=PlannedActivity)
def on_PlannedActivity_model_changed(sender, instance, **kwargs):
"""
receiver for sending email upon Activity creation and updatation
"""
eta = None
if instance.severity == "High":
eta = instance.start
if kwargs['created']:
subject = "New Activity creation success"
periodic_send_email.apply_async(["arg1", ], {'subject': subject, 'instance': instance, 'action': 'create'}, countdown=10, expires=60, headers={'header': 'myheader'} )
else:
subject = "Activity updation success"
periodic_send_email.apply_async(args=["arg1", "arg2"], kwargs={'subject': subject, 'instance': instance, 'action': 'update'}, eta=instance.start, retry= True)
#celery task
@shared_task
def periodic_send_email(self, *args, **kwargs):
print 'args: periodic_send_email:', args
print 'kwargs: periodic_send_email:', kwargs
print 'this is periodic send email task'
# print "self.args: ", args
# print "self.kwargs: ", kwargs
# team = instance.team
# title = instance.title
# description = instance.description
# start = str(instance.start)
# end = str(instance.end)
# severity = instance.severity
# status = instance.status
#
# body = "\nActivity details: \n\n" + '\nTitle: ' + title + '\nDescription: ' + description + '\nStart at: ' + start + '\nEnd at: ' + end + '\nSeverity: ' + severity + '\nStatus: ' + status
#
# print body
to_mail = 'pgopal1166@gmail.com'
# print "body:", body
# send_mail(subject, body, 'vgopal1166@gmail.com', [to_mail, 'vgopal1166@gmail.com'])
return "success email send"
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bdd9b006-7ab0-4875-978b-1ca67a263379%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment