Class: SolidQueue::Dispatcher::ConcurrencyMaintenance

Inherits:
Object
  • Object
show all
Includes:
AppExecutor
Defined in:
lib/solid_queue/dispatcher/concurrency_maintenance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AppExecutor

#handle_thread_error, #wrap_in_app_executor

Constructor Details

#initialize(interval, batch_size) ⇒ ConcurrencyMaintenance

Returns a new instance of ConcurrencyMaintenance.



9
10
11
12
# File 'lib/solid_queue/dispatcher/concurrency_maintenance.rb', line 9

def initialize(interval, batch_size)
  @interval = interval
  @batch_size = batch_size
end

Instance Attribute Details

#batch_sizeObject (readonly)

Returns the value of attribute batch_size.



7
8
9
# File 'lib/solid_queue/dispatcher/concurrency_maintenance.rb', line 7

def batch_size
  @batch_size
end

#intervalObject (readonly)

Returns the value of attribute interval.



7
8
9
# File 'lib/solid_queue/dispatcher/concurrency_maintenance.rb', line 7

def interval
  @interval
end

Instance Method Details

#startObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/solid_queue/dispatcher/concurrency_maintenance.rb', line 14

def start
  @concurrency_maintenance_task = Concurrent::TimerTask.new(run_now: true, execution_interval: interval) do
    expire_semaphores
    unblock_blocked_executions
  end

  @concurrency_maintenance_task.add_observer do |_, _, error|
    handle_thread_error(error) if error
  end

  @concurrency_maintenance_task.execute
end

#stopObject



27
28
29
# File 'lib/solid_queue/dispatcher/concurrency_maintenance.rb', line 27

def stop
  @concurrency_maintenance_task.shutdown
end