Skip to content

How to initialise firebase with server start.  #21

@jasjeet30

Description

@jasjeet30

I am trying to integrate firebase and I used this code in config/initializers/firebase.rb

require 'rest-firebase'

f = RestFirebase.new :site => 'https://xxxx-11111.firebaseio.com/',
      :secret => 'xxxxx1651x1xxx61x16x616xxxx',
      :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!

    es = f.event_source('/')

    es.onerror do |error|
      puts "ERROR: #{error}"
    end



es.onreconnect do
  !!@start # always reconnect unless stopping
end

es.onmessage do |event, data|
  puts "EVENT: #{event}, DATA: #{data}"
end

puts "Starting..."
@start = true
es.start

 rd, wr = IO.pipe

 Signal.trap('INT') do # intercept ctrl-c
   puts "Stopping..."
   @start = false      # stop reconnecting
   es.close            # close socket
   es.wait             # wait for shutting down
   wr.puts             # unblock main thread
 end

 rd.gets               # main thread blocks here

but when i try to start my rails server: rails s -b 0.0.0.0 -p 3030

the console stuck at:

rails s -b 0.0.0.0 -p 3030

=> Booting Puma
=> Rails 5.0.4 application starting in development on http://0.0.0.0:3030
=> Run `rails server -h` for more startup options
Starting...

and need to press Ctrl+C to start the puma. but by this firebase stop working. how I can integrate firebase listener with rails so whenever I start the server firebase starts with it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions