Class: ThreeScale::Backend::WorkerSync

Inherits:
Object
  • Object
show all
Includes:
Worker
Defined in:
lib/3scale/backend/worker_sync.rb

Instance Method Summary collapse

Methods included from Worker

new, #one_off?, #shutdown, #to_s, work

Methods included from Configurable

#configuration, #configuration=, included

Constructor Details

#initialize(options = {}) ⇒ WorkerSync

Returns a new instance of WorkerSync.



8
9
10
11
12
13
14
# File 'lib/3scale/backend/worker_sync.rb', line 8

def initialize(options = {})
  trap('TERM') { shutdown }
  trap('INT')  { shutdown }

  @one_off = options[:one_off]
  @job_fetcher = options[:job_fetcher] || JobFetcher.new
end

Instance Method Details

#workObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/3scale/backend/worker_sync.rb', line 16

def work
  register_worker

  loop do
    break if @shutdown

    job = @job_fetcher.fetch
    perform(job) if job

    break if one_off?
  end

  unregister_worker
end