0

In the code below, the create_draft draft function is slower than update_draft

If the first request falls at create_draft then the next one will need to wait for it before check if the draft already exists and fall in update_draft.

@app.route('/webhook', methods=['POST'])
def get_webhook():
    # some processing...

    # Get drafts
    gmail_drafts = gmail.get_drafts()
    if gmail_drafts['resultSizeEstimate'] > 0:
        gmail_drafts = map(gmail.get_draft, [draft['id'] for draft in gmail_drafts['drafts']])
        drafts_to = {draft['id']:draft['message']['payload']['headers'][4]['value'] for draft in list(gmail_drafts)}

        if curator_email_address not in list(drafts_to.values()):
            create_draft(curator_email_address, song_url, artist, song_name)
        else:
            draft_id = list(drafts_to.keys())[0]
            update_draft(draft_id, song_url, artist, song_name)
    else:
        create_draft(curator_email_address, song_url, artist, song_name)

    return request.json, 200
Marcelo Gazzola
  • 907
  • 12
  • 28

0 Answers0