2👍
✅
I might have found the solution. Simply refactor the sendMail() function inside event into the main task therefore there won’t be any need to parse the object into json:
@celery.task(name='tasks.check_for_events')
@periodic_task(run_every=datetime.timedelta(minutes=1))
def check_for_events():
now = datetime.datetime.utcnow().replace(tzinfo=utc,second=00, microsecond=00)
events = list(Event.objects.filter(reminder_date_time__range=(now - datetime.timedelta(minutes=5), now)))
for event in events:
subject = 'Event Reminder'
link = None
message = ...
sendEmail.delay(subject, message, event.user.email)
@celery.task(name='tasks.sendEmail')
def sendEmail(subject, message, email):
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email])
This works both with Rabbitmq and Amazon SQS
1👍
For someone returning to this post,
This happens when the serializer defined in your celery runtime config is not able to process objects passed to the celery task.
For example: if the config says JSON as required format and some Model object is supplied, above mentioned exception might be raised.
(Q): Is it explicitly necessary to define these parameters
# CELERY_ACCEPT_CONTENT=[‘json’, ],
# CELERY_TASK_SERIALIZER=’json’,
# CELERY_RESULT_SERIALIZER=’json’,
- [Django]-Update .po file in django without losing current translations
- [Django]-Type object 'Post' has no attribute 'published' Django
Source:stackexchange.com