Perpetual 503 error for pulling stats of certain campaigns

restapi
ads
service-status
stats

#1

Hi ,
A strange thing has been happening when I pull in stats for this account: 18ce547jz5z

TwitterAds::Request.new(client, :get, resource, params: params).perform

{:entity_ids=>“7765v,7765q,7765l,78d6v,78cz6,780xt,78099,780xw,780xv,76fkp,79zcl,6xvmd,78hfi,78g3s,78fld,78fad,76t90,76t7r,76t63,752r4”, :entity=>“CAMPAIGN”, :end_time=>“2017-02-05T08:00:00Z”, :granularity=>“HOUR”, :metric_groups=>“BILLING,ENGAGEMENT,MOBILE_CONVERSION”, :placement=>“ALL_ON_TWITTER”, :start_time=>“2017-01-31T08:00:00Z”}

As you can see, I am Fetching stats for Campaign IDS:[“7765v”, “7765q”, “7765l”, “78d6v”, “78cz6”, “780xt”, “78099”, “780xw”, “780xv”, “76fkp”, “79zcl”, “6xvmd”, “78hfi”, “78g3s”, “78fld”, “78fad”, “76t90”, “76t7r”, “76t63”, “752r4”]

for placement: ALL_ON_TWITTER

This has happened only for the above request since 3 days now. My task fails exactly at this point with the above entity IDS always.

I am perpetually getting hit the 503 error. As you can see from the log below I try to handle it using retry_after data.

<TwitterAds::ServiceUnavailable:0x67501980 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:53:17Z”]
retry after : 2017-02-04 03:53:17 -0800
current time: 2017-02-04 03:53:17 -0800

retrying. Tries remaining: 19

<TwitterAds::ServiceUnavailable:0x98313060 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:53:21Z”]
retry after : 2017-02-04 03:53:21 -0800
current time: 2017-02-04 03:53:21 -0800

retrying. Tries remaining: 18

<TwitterAds::ServiceUnavailable:0x99723280 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:53:27Z”]
retry after : 2017-02-04 03:53:27 -0800
current time: 2017-02-04 03:53:26 -0800

sleeping : 11

retrying. Tries remaining: 17

<TwitterAds::ServiceUnavailable:0x103382860 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:53:42Z”]
retry after : 2017-02-04 03:53:42 -0800
current time: 2017-02-04 03:53:42 -0800

retrying. Tries remaining: 16

<TwitterAds::ServiceUnavailable:0x102968840 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:53:46Z”]
retry after : 2017-02-04 03:53:46 -0800
current time: 2017-02-04 03:53:46 -0800

retrying. Tries remaining: 15

<TwitterAds::ServiceUnavailable:0x102513280 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:53:53Z”]
retry after : 2017-02-04 03:53:53 -0800
current time: 2017-02-04 03:53:51 -0800
sleeping : 12
retrying. Tries remaining: 14
<TwitterAds::ServiceUnavailable:0x102090420 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:54:07Z”]
retry after : 2017-02-04 03:54:07 -0800
current time: 2017-02-04 03:54:07 -0800
retrying. Tries remaining: 13
<TwitterAds::ServiceUnavailable:0x101635380 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">rake aborted!

e.retry_after: [“2017-02-04T11:54:12Z”]
retry after : 2017-02-04 03:54:12 -0800
current time: 2017-02-04 03:54:12 -0800
retrying. Tries remaining: 12

<TwitterAds::ServiceUnavailable:0x101213240 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:54:17Z”]
retry after : 2017-02-04 03:54:17 -0800
current time: 2017-02-04 03:54:17 -0800
retrying. Tries remaining: 11

<TwitterAds::ServiceUnavailable:0x100758540 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:54:21Z”]
retry after : 2017-02-04 03:54:21 -0800
current time: 2017-02-04 03:54:21 -0800
retrying. Tries remaining: 10
<TwitterAds::ServiceUnavailable:0x100336260 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:54:26Z”]
retry after : 2017-02-04 03:54:26 -0800
current time: 2017-02-04 03:54:26 -0800
retrying. Tries remaining: 9
<TwitterAds::ServiceUnavailable:0x99889640 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:54:30Z”]
retry after : 2017-02-04 03:54:30 -0800
current time: 2017-02-04 03:54:30 -0800
retrying. Tries remaining: 8
<TwitterAds::ServiceUnavailable:0x99467420 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:54:38Z”]
retry after : 2017-02-04 03:54:38 -0800
current time: 2017-02-04 03:54:35 -0800
sleeping : 13
retrying. Tries remaining: 7
<TwitterAds::ServiceUnavailable:0x99012180 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:54:53Z”]
retry after : 2017-02-04 03:54:53 -0800
current time: 2017-02-04 03:54:53 -0800
retrying. Tries remaining: 6
<TwitterAds::ServiceUnavailable:0x98557260 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:54:57Z”]
retry after : 2017-02-04 03:54:57 -0800
current time: 2017-02-04 03:54:57 -0800
retrying. Tries remaining: 5
<TwitterAds::ServiceUnavailable:0x98142000 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:55:02Z”]
retry after : 2017-02-04 03:55:02 -0800
current time: 2017-02-04 03:55:02 -0800
retrying. Tries remaining: 4
<TwitterAds::ServiceUnavailable:0x97682180 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:55:06Z”]
retry after : 2017-02-04 03:55:06 -0800
current time: 2017-02-04 03:55:06 -0800
retrying. Tries remaining: 3
<TwitterAds::ServiceUnavailable:0x97183320 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:55:11Z”]
retry after : 2017-02-04 03:55:11 -0800
current time: 2017-02-04 03:55:11 -0800
retrying. Tries remaining: 2
<TwitterAds::ServiceUnavailable:0x96728140 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:55:16Z”]
retry after : 2017-02-04 03:55:16 -0800
current time: 2017-02-04 03:55:16 -0800
retrying. Tries remaining: 1
<TwitterAds::ServiceUnavailable:0x96305760 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">
e.retry_after: [“2017-02-04T11:55:20Z”]
retry after : 2017-02-04 03:55:20 -0800
current time: 2017-02-04 03:55:20 -0800
retrying. Tries remaining: 0
<TwitterAds::ServiceUnavailable:0x41094060 code=503 details="[{:code=>“SERVICE_UNAVAILABLE”, :message=>“Service unavailable due to request timeout; please try the request again later”}]">

As you can see the retry_after that I receive is more or less equal to the current time in PST timezone, So I retry again. Even If there is a 1 second difference between the current time and the retry_after I wait for 10 seconds. So I am following the documentation best practises.

Also I am not pulling voluminous data. Its just data since 6 days before.
Can someone help me here.


#2

Can someone help here. Please? Thanks


#3

Hi,

Persistent 503 on the synchronous stats endpoint can sometimes be related to a single entity within the list of entities you are passing (if it’s truly some sort of internal service error), so as part of your retry scheme I would:

  • Switch to use exponential backoff instead of retry-after (I think retry-after is not waiting for very long in the above example)
  • After the exponential backoff fails after some # of retries, switch to single entities instead of calling list of entities

The amount of data being returned at once is likely what’s causing an internal timeout here. We recommend for syncing large amounts of data to use the async method, which is create_async_job in https://github.com/twitterdev/twitter-ruby-ads-sdk/blob/master/lib/twitter-ads/resources/analytics.rb
The process is to create a job, then poll the status to wait for it to complete, then finally download the data, however the average is for the job to finish in a matter of seconds. Then caching these in a DB on your side is best, without caching it may be hard to not hit rate limits or fetch historical data.

Let us know if this helps and especially whether reducing # of entities allows synchronous to work or not.

Thanks,

John