module MultiBackgroundJob
This is a central point of our background job queue system. We have more external services like API and Lme that queue jobs for pipeline processing. So that way all services can share the same codebase and avoid incompatibility issues
Example:
Standard job.
MultiBackgroundJob['UserWorker', queue: 'default'] .with_args(1) .push(to: :sidekiq)
Schedule the time when a job will be executed.
MultiBackgroundJob['UserWorker'] .with_args(1) .at(timestamp) .push(to: :sidekiq) MultiBackgroundJob['UserWorker'] .with_args(1) .in(10.minutes) .push(to: :sidekiq)
Unique jobs.
MultiBackgroundJob['UserWorker', uniq: { across: :queue, timeout: 1.minute, unlock_policy: :start }] .with_args(1) .push(to: :sidekiq)
Server midleware for Faktory
@see github.com/contribsys/faktory_worker_ruby/wiki/Middleware
Provides the Sidekiq middleware that make the unique job control work
@see github.com/contribsys/faktory_worker_ruby/wiki/Middleware
frizen_string_literal: true
Constants
- SERVICES
- VERSION
Public Class Methods
[](worker_class, **options)
click to toggle source
@param worker_class [String] The worker class name @param options [Hash] Options that will be passed along to the worker instance @return [MultiBackgroundJob::Worker] An instance of worker
# File lib/multi_background_job.rb, line 50 def self.[](worker_class, **options) Worker.new(worker_class, **config.worker_options(worker_class).merge(options)) end
config()
click to toggle source
# File lib/multi_background_job.rb, line 72 def self.config @config ||= Config.new end
configure(&block)
click to toggle source
# File lib/multi_background_job.rb, line 76 def self.configure(&block) return unless block_given? config.instance_eval(&block) @redis_pool = nil config end
for(service, **options)
click to toggle source
# File lib/multi_background_job.rb, line 58 def self.for(service, **options) require_relative "multi_background_job/workers/#{service}" service = service.to_sym worker_options = options.merge(service: service) module_name = service.to_s.split(/_/i).collect!{ |w| w.capitalize }.join mod = Workers.const_get(module_name) mod.module_eval do define_method(:bg_worker_options) do worker_options end end mod end
jid()
click to toggle source
# File lib/multi_background_job.rb, line 54 def self.jid SecureRandom.hex(12) end
redis_pool()
click to toggle source
# File lib/multi_background_job.rb, line 84 def self.redis_pool @redis_pool ||= ConnectionPool.new(config.redis_pool) do Redis.new(config.redis_config) end end