Class: Cloudmunda::Supervisor

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudmunda/cli/supervisor.rb

Instance Method Summary collapse

Constructor Details

#initializeSupervisor

Returns a new instance of Supervisor.



7
8
9
# File 'lib/cloudmunda/cli/supervisor.rb', line 7

def initialize
  @processors = []
end

Instance Method Details

#quietObject



24
25
26
27
# File 'lib/cloudmunda/cli/supervisor.rb', line 24

def quiet
  logger.info 'Terminating workers'
  @processors.each(&:stop)
end

#startObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cloudmunda/cli/supervisor.rb', line 11

def start
  workers.each do |worker_class|
    if ::Cloudmunda.env == 'development' && !worker_class.get_runs_in_development
      logger.info "Not starting a processor for worker #{worker_class.get_type} as it doesn't run in development."
      next
    end

    logger.info "Starting a processor for worker #{worker_class.get_type}"
    processor = ::Cloudmunda::Processor.new(worker_class: worker_class)
    @processors << processor.start
  end
end

#stop(timeout: ::Cloudmunda.timeout) ⇒ Object



29
30
31
32
33
# File 'lib/cloudmunda/cli/supervisor.rb', line 29

def stop(timeout: ::Cloudmunda.timeout)
  quiet
  logger.info "Pausing #{timeout}s to allow workers to finish..."
  sleep timeout
end