Class: RocketJob::Subscribers::Server

Inherits:
Object
  • Object
show all
Includes:
RocketJob::Subscriber
Defined in:
lib/rocket_job/subscribers/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RocketJob::Subscriber

#process_action, #process_event, test_mode!, test_mode?

Constructor Details

#initialize(supervisor) ⇒ Server

Returns a new instance of Server.



8
9
10
# File 'lib/rocket_job/subscribers/server.rb', line 8

def initialize(supervisor)
  @supervisor = supervisor
end

Instance Attribute Details

#supervisorObject (readonly)

Returns the value of attribute supervisor.



6
7
8
# File 'lib/rocket_job/subscribers/server.rb', line 6

def supervisor
  @supervisor
end

Instance Method Details

#kill(server_id: nil, name: nil, wait_timeout: 5) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rocket_job/subscribers/server.rb', line 12

def kill(server_id: nil, name: nil, wait_timeout: 5)
  return unless my_server?(server_id, name)

  supervisor.synchronize do
    Supervisor.shutdown!

    supervisor.logger.info("Stopping Pool")
    supervisor.worker_pool.stop
    unless supervisor.worker_pool.living_count.zero?
      supervisor.logger.info("Giving pool #{wait_timeout} seconds to terminate")
      sleep(wait_timeout)
    end
    supervisor.logger.info("Kill Pool")
    supervisor.worker_pool.kill
  end

  logger.info "Killed"
end

#pause(server_id: nil, name: nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/rocket_job/subscribers/server.rb', line 31

def pause(server_id: nil, name: nil)
  return unless my_server?(server_id, name)

  supervisor.synchronize { supervisor.server.pause! if supervisor.server.may_pause? }
  Supervisor.event!
  logger.info "Paused"
end

#refresh(server_id: nil, name: nil) ⇒ Object



39
40
41
42
43
44
# File 'lib/rocket_job/subscribers/server.rb', line 39

def refresh(server_id: nil, name: nil)
  return unless my_server?(server_id, name)

  Supervisor.event!
  logger.info "Refreshed"
end

#resume(server_id: nil, name: nil) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/rocket_job/subscribers/server.rb', line 46

def resume(server_id: nil, name: nil)
  return unless my_server?(server_id, name)

  supervisor.synchronize { supervisor.server.resume! if supervisor.server.may_resume? }
  Supervisor.event!
  logger.info "Resumed"
end

#stop(server_id: nil, name: nil) ⇒ Object



54
55
56
57
58
59
# File 'lib/rocket_job/subscribers/server.rb', line 54

def stop(server_id: nil, name: nil)
  return unless my_server?(server_id, name)

  Supervisor.shutdown!
  logger.info "Shutdown"
end

#thread_dump(server_id: nil, name: nil) ⇒ Object



61
62
63
64
65
66
# File 'lib/rocket_job/subscribers/server.rb', line 61

def thread_dump(server_id: nil, name: nil)
  return unless my_server?(server_id, name)

  logger.info "Thread dump"
  supervisor.worker_pool.log_backtraces
end