services.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:decadegraphy 作者: decadegraphy 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号