Class: BackgroundQueue::ServerLib::EventServer

Inherits:
Object
  • Object
show all
Defined in:
lib/background_queue/server_lib/event_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ EventServer

Returns a new instance of EventServer.



10
11
12
13
# File 'lib/background_queue/server_lib/event_server.rb', line 10

def initialize(server)
  @server = server
  @running = false
end

Instance Attribute Details

#runningObject (readonly)

Returns the value of attribute running.



8
9
10
# File 'lib/background_queue/server_lib/event_server.rb', line 8

def running
  @running
end

Instance Method Details

#startObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/background_queue/server_lib/event_server.rb', line 15

def start
  EventMachine.run do
    EventMachine::start_server(@server.config.address.host, @server.config.address.port, BackgroundQueue::ServerLib::EventConnection) do |conn|
      conn.server = @server
    end

    @scheduler = Rufus::Scheduler::EmScheduler.new
    @scheduler.start
    for job in @server.config.jobs
      job.schedule(@scheduler, @server)
    end
    @running = true
  end
  @running = false
end

#stopObject



31
32
33
# File 'lib/background_queue/server_lib/event_server.rb', line 31

def stop
  EventMachine::stop if EventMachine::reactor_running?
end