urbanairship / ruby-library

A Ruby wrapper for the Urban Airship API.
Other
200 stars 117 forks source link

UA Push Notification Not Sent When Server Ran As Daemon #108

Closed maynardewm closed 6 years ago

maynardewm commented 6 years ago

Expected Behavior

Push notification should be sent to device.

Current Behavior

It works if I run the server as: rails s -b 0.0.0.0, but not if I run the server as rails s -d -b 0.0.0.0

I get the following error:

Response Code: 500
No such file or directory @ rb_sysopen - log/urbanairship.log

Possible Solution

Is it a permissions issue?

Rails Server Code

if @notification.save
      puts("It was saved")
      if @post.user.devices.count > 0
          puts("There is more than 0 devices")
          airship = UA::Client.new(key: Rails.application.secrets.ua_app_key, secret: Rails.application.secrets.ua_master_secret)
          (@post.user.devices).each do |device|
              if device.ua_channel_id != nil
                  puts("User has devices")
                  push = airship.create_push
                  push.audience = UA.or( UA.ios_channel(device.ua_channel_id) )
                  push.notification = UA.notification(alert: 'This went to an iOS device')
                  push.device_types = UA.device_types(['ios'])
                  push.send_push
                  puts("Successfully created UA notification")
              end
          end
      end
    end
pdxmele commented 6 years ago

Does it fail every time? Can you configure logging, turn it up, and let us know what's in the log please? Library version and time would also be great so we can check what's happening on our side for your request.

maynardewm commented 6 years ago

Library version: 4.1.0

When I try to tail the development.log file, I get an error:


Completed 401 Unauthorized in 37ms (ActiveRecord: 7.4ms)
Errno::ENOENT (No such file or directory @ rb_sysopen - log/urbanairship.log):
maynardewm commented 6 years ago

Here's the log output when I try to make the UA Notification:

Started POST "/api/1/posts/8289797122/likes.json" for 23.240.151.231 at 2018-03-15 18:10:49 +0000 Cannot render console from 23.240.151.231! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by Api::LikesController#create as JSON Parameters: {"post_key"=>"8289797122"} Can't verify CSRF token authenticity. User Load (0.3ms) SELECT users. FROM users WHERE users.id = 1 LIMIT 1 Post Load (0.2ms) SELECT posts. FROM posts WHERE posts.key = '8289797122' LIMIT 1 (0.2ms) SELECT COUNT() FROM likes WHERE likes.post_id = 36 AND likes.user_id = 1 (0.1ms) BEGIN Post Load (0.2ms) SELECT posts. FROM posts WHERE posts.id = 36 LIMIT 1 CACHE User Load (0.0ms) SELECT users. FROM users WHERE users.id = 1 LIMIT 1 [["id", 1], ["LIMIT", 1]] SQL (0.2ms) INSERT INTO likes (post_id, user_id, created_at, updated_at) VALUES (36, 1, '2018-03-15 18:10:49', '2018-03-15 18:10:49') (2.4ms) COMMIT User Load (0.2ms) SELECT users. FROM users WHERE users.id = 2 LIMIT 1 (0.1ms) BEGIN SQL (2.1ms) INSERT INTO notifications (user_id, notified_by_id, notifiable_type, notifiable_id, notification_type, created_at, updated_at) VALUES (2, 1, 'Post', 36, 'like', '2018-03-15 18:10:49', '2018-03-15 18:10:49') (2.9ms) COMMIT (0.2ms) SELECT COUNT() FROM devices WHERE devices.user_id = 2 Device Load (0.2ms) SELECT devices. FROM devices WHERE devices.user_id = 2 Completed 401 Unauthorized in 47ms (ActiveRecord: 12.5ms)

Errno::ENOENT (No such file or directory @ rb_sysopen - log/urbanairship.log):

app/controllers/api/likes_controller.rb:86:in block in create_notification' app/controllers/api/likes_controller.rb:79:increate_notification' app/controllers/api/likes_controller.rb:25:in `create'

pdxmele commented 6 years ago

Thanks! Looks like something may still be weird with your library logging setup.. did you follow the steps here? https://github.com/urbanairship/ruby-library#configuration

maynardewm commented 6 years ago

The config is correct I believe:

require 'urbanairship'
Urbanairship.configure do |config|
    config.log_path = 'log'
    config.log_level = Logger::WARN
end

It works when I run the server like this: rails s -b 0.0.0.0

But not like this: rails s -d -b 0.0.0.0

pdxmele commented 6 years ago

Ok, thanks for your patience! We're hoping to be able to dig into this early next week.

wilsab30 commented 6 years ago

Hi,

Could you tell me what version of ruby and rails you are running? Also is the daemon you're using a gem? If so, which gem/version are you using? If not, please send the daemon code you are using. Are you running the app from the root of the app directory?

maynardewm commented 6 years ago

Ruby 2.5.0 Rails 5.1.4 Puma in production, Webrick in dev

Yes I am running from root of app directory

wilsab30 commented 6 years ago

Hi,

I've been talking about this with the engineers here and the issue, in terms of logging, may be that you are specifying the config.log_path value as 'log', but Ruby loggers won't automatically create that directory. Could you please create the log directory and try to send again.

maynardewm commented 6 years ago

I couldn't get any config.log_path settings to work, so I removed it for now so at least it works.

wilsab30 commented 6 years ago

Hi,

I just want to clarify. Are you able to run the server as rails s -d -b 0.0.0.0 and have push notifications go out now?