def process_photograph_event(applicant, calendar_service, redis):
"""Processes the potential photograph event.
It tries to submit the event to designated google calendar.
And it commits to the database to prevent duplication event in the calendar.
The function is atomic.
"""
# Uses the best effort redis redlock assumed the network is quite ok for such task.
with redis.lock("{}{}".format(_PHOTOGRAPH_EVENT_LOCK_KEY_PREFIX, applicant.id)):
applicant.refresh_from_db()
if applicant.google_calendar_event_created_at:
return
with transaction.atomic():
event = populate_event_for_submitting(applicant)
result = submit_photograph_event_to_calendar(calendar_service, event)
commit_created_at_timestamp_in_db(applicant, result)
评论列表
文章目录