I'm trying to get urbanairship to work with my Ionic app using Ruby on Rails as back-end.

Followed the documentation and set up the gem: https://docs.urbanairship.com/reference/libraries/ruby/3.1.0/ 

In production I see that users don't get their notifications. So I've decided to check it out on development.

When I'm trying to send a notifications like in the example, I get this error:

 

RuntimeError: Request Timeout
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/unirest-1.1.2/lib/unirest.rb:73:in `rescue in internal_request'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/unirest-1.1.2/lib/unirest.rb:59:in `internal_request'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/unirest-1.1.2/lib/unirest.rb:48:in `request'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/unirest-1.1.2/lib/unirest.rb:100:in `post'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/urbanairship-3.1.1/lib/urbanairship/client.rb:56:in `call'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/urbanairship-3.1.1/lib/urbanairship/client.rb:56:in `send_request'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/urbanairship-3.1.1/lib/urbanairship/push/push.rb:41:in `send_push'
from (irb):10
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/ubuntu/app/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'

 

The server is hosted on AWS, I don't think there supposed to be any timeouts...

Please help!

Didn't find what you were looking for?

New post

Comments

2 comments

  • It looks like you received a 5xx error from our system. I will provide you a code snippet that will help you retry the request when this error occurs.

    def exp_backoff(upto)
        result=[ ]
        (1..upto).each do |iter|
        result << (1.0/2.0*(2.0**iter - 1.0)).ceil
        end
        return result
    end
    
    retries=5
    backoff = exp_backoff(retries)
    exb=0
    
    if exb <= retries
            sleep(backoff[exb])
        exb += 1
    end
    

    This code implements exponential back-off. What this means is that for each time you attempt to resend the request to our system, the amount of time between each retry will increase exponentially. Please note that you will have to implement this in the code for your application in order for it to work. This should allow your request to go through our system and send the push notification successfully.

    I hope this helps. Please let me know if you have any other questions or concerns.

    0
  • Thank you very much but as a junior developer I'm a little confused where should I put the method that sends the push,

    I use the code example from here: http://docs.urbanairship.com/reference/libraries/ruby/3.1.0/ 

    require 'urbanairship'
    UA = Urbanairship
    airship = UA::Client.new(key:'application_key', secret:'master_secret')
    p = airship.create_push
    p.audience = UA.all
    p.notification = UA.notification(alert: 'Hello')
    p.device_types = UA.all
    p.send_push
     
    should I put it instead of Pushy.POST(push_url, :basic_auth => auth) ?
    0

Please sign in to leave a comment.