Module: ThreeScale::Backend::Worker

Includes:
Resque::Helpers, Configurable
Included in:
WorkerAsync, WorkerSync
Defined in:
lib/3scale/backend/worker.rb

Overview

This is a module that’s meant to be included from the different workers. Now we have WorkerSync and WorkerAsync. Those classes need to implement #work, which is responsible for fetching jobs from the queue and running them by calling perform(job).

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configurable

#configuration, #configuration=, included

Class Method Details

.new(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/3scale/backend/worker.rb', line 20

def self.new(options = {})
  Logging::Worker.configure_logging(self, options[:log_file])
  Logging::External.setup_worker

  if configuration.worker_prometheus_metrics.enabled
    require '3scale/backend/worker_metrics'
    WorkerMetrics.start_metrics_server
  end

  if options[:async]
    # Conditional require is done to require async-* libs only when
    # needed and avoid possible side-effects.
    require '3scale/backend/worker_async'
    WorkerAsync.new(options)
  else
    require '3scale/backend/worker_sync'
    WorkerSync.new(options)
  end
end

.work(options = {}) ⇒ Object

Options

  • :one_off - if true, will process one job, then quit



44
45
46
47
48
# File 'lib/3scale/backend/worker.rb', line 44

def self.work(options = {})
  Process.setproctitle("3scale_backend_worker #{Backend::VERSION}")
  options[:async] = configuration.redis.async
  new(options).work
end

Instance Method Details

#one_off?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/3scale/backend/worker.rb', line 62

def one_off?
  @one_off
end

#shutdownObject



54
55
56
# File 'lib/3scale/backend/worker.rb', line 54

def shutdown
  @shutdown = true
end

#to_sObject



58
59
60
# File 'lib/3scale/backend/worker.rb', line 58

def to_s
  @to_s ||= "#{hostname}:#{Process.pid}"
end

#workObject



50
51
52
# File 'lib/3scale/backend/worker.rb', line 50

def work
  raise 'Missing implementation of #work'
end