Class: Rubino::Jobs::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/jobs/worker.rb

Overview

Background worker that polls the job queue and executes available jobs. Runs in a loop until interrupted.

Instance Method Summary collapse

Constructor Details

#initialize(config: nil) ⇒ Worker

Returns a new instance of Worker.



8
9
10
11
12
13
# File 'lib/rubino/jobs/worker.rb', line 8

def initialize(config: nil)
  @config = config || Rubino.configuration
  @poll_interval = @config.jobs_poll_interval
  @running = false
  @worker_id = "worker-#{Process.pid}-#{Thread.current.object_id}"
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rubino/jobs/worker.rb', line 31

def running?
  @running
end

#startObject

Starts the worker loop



16
17
18
19
20
21
22
23
24
# File 'lib/rubino/jobs/worker.rb', line 16

def start
  @running = true
  setup_signal_handlers

  while @running
    processed = process_batch
    sleep(@poll_interval) if processed.zero?
  end
end

#stopObject

Stops the worker gracefully



27
28
29
# File 'lib/rubino/jobs/worker.rb', line 27

def stop
  @running = false
end