Class: Beez::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/beez/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker_class:, client: ::Beez.client) ⇒ Processor

Returns a new instance of Processor.



5
6
7
8
9
10
11
12
13
14
# File 'lib/beez/processor.rb', line 5

def initialize(worker_class:, client: ::Beez.client)
  @client = client
  @worker_class = worker_class
  @busy_count = ::Concurrent::AtomicFixnum.new(0)
  @timer = ::Concurrent::TimerTask.new(
    run_now: true,
    execution_interval: worker_poll_interval,
    timeout_interval: worker_timeout
  ) { run }
end

Instance Attribute Details

#busy_countObject (readonly)

Returns the value of attribute busy_count.



3
4
5
# File 'lib/beez/processor.rb', line 3

def busy_count
  @busy_count
end

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/beez/processor.rb', line 3

def client
  @client
end

#timerObject (readonly)

Returns the value of attribute timer.



3
4
5
# File 'lib/beez/processor.rb', line 3

def timer
  @timer
end

#worker_classObject (readonly)

Returns the value of attribute worker_class.



3
4
5
# File 'lib/beez/processor.rb', line 3

def worker_class
  @worker_class
end

Instance Method Details

#should_activate_jobs?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/beez/processor.rb', line 26

def should_activate_jobs?
  busy_count.value <= worker_max_jobs_to_activate
end

#startObject



16
17
18
19
# File 'lib/beez/processor.rb', line 16

def start
  timer.execute
  self
end

#stopObject



21
22
23
24
# File 'lib/beez/processor.rb', line 21

def stop
  timer.shutdown
  self
end