Class: SqsPoller::Process::WorkerController

Inherits:
Object
  • Object
show all
Defined in:
lib/sqspoller/process/worker_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker_count, task_queue, worker_task, auto_tuning = true) ⇒ WorkerController

Returns a new instance of WorkerController.



20
21
22
23
24
25
26
27
28
29
# File 'lib/sqspoller/process/worker_controller.rb', line 20

def initialize(worker_count, task_queue, worker_task, auto_tuning = true)
  @task_queue = task_queue
  @message_handler = worker_task
  @dynamic_scheduling = auto_tuning
  @worker_count = worker_count
  @task_workers = Concurrent::RubyThreadPoolExecutor.new(min_threads: @worker_count)
  @task_finalizer = TaskFinalizer.new(task_queue.max)
  @logger = SqsPoller::Logger.get_new_logger(self.class.name)
  @started = false
end

Class Method Details

.getObject



31
32
33
34
# File 'lib/sqspoller/process/worker_controller.rb', line 31

def self.get
  return @instance if @instance
  raise "WorkerController not yet started"
end

.start(worker_count, task_queue, worker_task, auto_tuning = true) ⇒ Object



36
37
38
39
40
41
# File 'lib/sqspoller/process/worker_controller.rb', line 36

def self.start (worker_count, task_queue, worker_task, auto_tuning = true)
  return @instance if @instance
  @instance = new(worker_count, task_queue, worker_task, auto_tuning)
  @instance.start
  @instance
end

Instance Method Details

#shutdownObject



57
58
59
# File 'lib/sqspoller/process/worker_controller.rb', line 57

def shutdown
  @logger.info "WorkerController Terminated"
end

#startObject



47
48
49
50
51
52
53
54
55
# File 'lib/sqspoller/process/worker_controller.rb', line 47

def start
  @logger.info "Starting #{@worker_count} workers"
  begin
    start_workers
    @started = true
  rescue Exception => e
    @logger.error "Task Worker killed for and restarted. Caught error: #{e.message}, #{e.backtrace.join("\n")}"
  end
end

#started?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/sqspoller/process/worker_controller.rb', line 43

def started?
  @started
end