CodementorIO / rest-firebase

Ruby Firebase REST API client built on top of rest-core
Apache License 2.0
107 stars 22 forks source link

Firebase not working in forever mode. #20

Closed jasjeet30 closed 7 years ago

jasjeet30 commented 7 years ago

I put this code in config/initializers folder.

` require 'rest-firebase'

f = RestFirebase.new :site => 'https://xxx-xxx-1111.firebaseio.com',
  :secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  :d => {:auth_data => 'something'},
  :log_method => method(:puts),
  :timeout => 10,
  :max_retries => 3,
  :retry_exceptions =>
  [IOError, SystemCallError, Timeout::Error],
  :error_callback => method(:p),
  :auth_ttl => 82800,
  :auth => false # Ignore auth for this example!

RestFirebase.pool_size = 5
RestFirebase.pool_idle_time = 60

@reconnect = true

es = f.event_source('notification/')

es.onmessage do |event, data, sock|

  es.onreconnect do
    !!@start # always reconnect unless stopping
  end
  if event == 'put' && !data['data'].nil?
    if !data['data']['notification_id'].nil?
      push = User.firebase_direct_message_push(data)
      # p push
    end
  end
end # Called for each message

es.start`

and i run the server as rails s -b 0.0.0.0 -p 3000 it works but when i run my server forever with rails s -b 0.0.0.0 -p 3000 -d it didn't work.

godfat commented 7 years ago

You shouldn't be using it this way because you would have no control over the instance, and that @reconnect could be set in a weird place. You should be putting this inside your own class or something.

That aside, daemonizing could be tricky, and it would be depending on the server you're running. Which server are you using right now? By didn't work, what do you mean? Please describe how that didn't work?

jasjeet30 commented 7 years ago

thanks for reply I change the code structure so it working now.

godfat commented 7 years ago

Oh, good to know it's working now :)