Class: CelluloidIOPGListener::Examples::Server

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::IO, Celluloid::Internals::Logger, Initialization::ArgumentExtraction
Defined in:
lib/celluloid-io-pg-listener/examples/server.rb

Instance Method Summary collapse

Methods included from Initialization::ArgumentExtraction

#channel, #conninfo_hash, #dbname

Constructor Details

#initialize(*args) ⇒ Server

Returns a new instance of Server.



11
12
13
# File 'lib/celluloid-io-pg-listener/examples/server.rb', line 11

def initialize(*args)
  debug "Server will send notifications to #{dbname}:#{channel}"
end

Instance Method Details

#pingObject

Helps with testing by making the notify synchronous.



34
35
36
37
# File 'lib/celluloid-io-pg-listener/examples/server.rb', line 34

def ping
  notify(channel, Time.now.to_i)
  debug "Notified #{channel}"
end

#runObject



24
25
26
27
28
29
30
31
# File 'lib/celluloid-io-pg-listener/examples/server.rb', line 24

def run
  now = Time.now.to_f
  sleep now.ceil - now + @sleep_interval
  # There is no way to pass anything into the block, which is why this server isn't all that useful.
  # The client is intended to listen to notifications coming from other sources,
  #   like a PG TRIGGER than sends a notification on INSERT, for example.
  every(@run_interval) { ping }
end

#start(run_interval: 1, sleep_interval: 0.1) ⇒ Object

Defaults:

1/10th of a second sleep intervals
1 second run intervals


18
19
20
21
22
# File 'lib/celluloid-io-pg-listener/examples/server.rb', line 18

def start(run_interval: 1, sleep_interval: 0.1)
  @sleep_interval = sleep_interval
  @run_interval = run_interval
  async.run
end