Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: timing expectations #56

Open
mbiokyle29 opened this issue Mar 30, 2018 · 0 comments
Open

Question: timing expectations #56

mbiokyle29 opened this issue Mar 30, 2018 · 0 comments

Comments

@mbiokyle29
Copy link

This is more of a question (apologies if this is the wrong place for this) about what kind of timing expectations can be expected from the API in regards to data syncing. The position I am in is:

  • Service A sends a request to Service B
  • In response to the request, Service B sends an email via Transactional
  • After getting the response from Service B, Service A attempts to query the message_timeline to validate that the email went through (yes Service B likely should handle this)

I have the lookup wrapped in a "try, wait" loop to give the API some time to sync. I also lookup the last send email id (before making the request) to have an anchor to search from. Here is the code (more or less):

tx = Transactional({"api_key": "#######################"})

# get the last sent id before making the request
timeline = tx.message_timeline(
    params={
        "group": group
    }
)
sent_after_id = timeline[0].MessageID

# send the request (blocking)
actual_email = "foo@bar.com"
group = "foobar"
result = sent_request_to_service_b(actual_email, group)

found = False
attempts = 30
wait = 10
for i in range(attempts):
    timeline = tx.message_timeline(
        params={
            "group": group,
            "sentAfterId": sent_after_id
        }
    )

    sent_emails = [e.Recipient for e in timeline]
    found = any([actual_email == e for e in sent_emails])

    if found:
        break
    else:
        time.sleep(wait)

There are cases where this works (the email is found) on the very first try (i.e. the API is synced within a few seconds at most) and there are times where it takes 100+ seconds of waiting in order for the email to be found. I can go into the web browser and see the email in the Latest emails sent table long before the API resolves it. I am just wondering if there is some kind of rate limiting that is going on or some other magic happening? I ask because the behavior is fairly back and forth, it works on the first try, then it takes 100 seconds, then it works on the first try, etc (all with different emails that were sent the same way in the same time frame).

Everything is running createsend==4.2.7

I'd appreciate any advice you might have. Thanks for working on this api!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant