Class: SqsPoller::Process::WorkerController
- Inherits:
-
Object
- Object
- SqsPoller::Process::WorkerController
- Defined in:
- lib/sqspoller/process/worker_controller.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(worker_count, task_queue, worker_task, auto_tuning = true) ⇒ WorkerController
constructor
A new instance of WorkerController.
- #shutdown ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
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
.get ⇒ Object
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
#shutdown ⇒ Object
57 58 59 |
# File 'lib/sqspoller/process/worker_controller.rb', line 57 def shutdown @logger.info "WorkerController Terminated" end |
#start ⇒ Object
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.}, #{e.backtrace.join("\n")}" end end |
#started? ⇒ Boolean
43 44 45 |
# File 'lib/sqspoller/process/worker_controller.rb', line 43 def started? @started end |