module Roundhouse
Constants
- DEFAULTS
- DEFAULT_WORKER_OPTIONS
- LICENSE
- NAME
- VERSION
Public Class Methods
How frequently Redis should be checked by a random Roundhouse
process for scheduled and retriable jobs. Each individual process will take turns by waiting some multiple of this value.
See roundhouse/scheduled.rb for an in-depth explanation of this value
# File lib/roundhouse.rb, line 165 def self.average_scheduled_poll_interval=(interval) self.options[:average_scheduled_poll_interval] = interval end
# File lib/roundhouse.rb, line 114 def self.client_middleware @client_chain ||= Middleware::Chain.new yield @client_chain if block_given? @client_chain end
Configuration for Roundhouse
client, use like:
Roundhouse.configure_client do |config| config.redis = { :namespace => 'myapp', :size => 1, :url => 'redis://myhost:8877/0' } end
# File lib/roundhouse.rb, line 69 def self.configure_client yield self unless server? end
Configuration for Roundhouse
server, use like:
Roundhouse.configure_server do |config| config.redis = { :namespace => 'myapp', :size => 25, :url => 'redis://myhost:8877/0' } config.server_middleware do |chain| chain.add MyServerHook end end
# File lib/roundhouse.rb, line 59 def self.configure_server yield self if server? end
# File lib/roundhouse.rb, line 130 def self.default_worker_options defined?(@default_worker_options) ? @default_worker_options : DEFAULT_WORKER_OPTIONS end
# File lib/roundhouse.rb, line 126 def self.default_worker_options=(hash) @default_worker_options = default_worker_options.merge(hash.stringify_keys) end
# File lib/roundhouse.rb, line 138 def self.dump_json(object) JSON.generate(object) end
Register a proc to handle any error which occurs within the Roundhouse
process.
Roundhouse.configure_server do |config| config.error_handlers << proc {|ex,ctx_hash| MyErrorService.notify(ex, ctx_hash) } end
The default error handler logs errors to Roundhouse.logger
.
# File lib/roundhouse.rb, line 176 def self.error_handlers self.options[:error_handlers] end
# File lib/roundhouse/rails.rb, line 2 def self.hook_rails! # no op # This may be completely removed in the future # Those extensions make sense for Sidekiq, but do # not make sense for Roundhouse end
# File lib/roundhouse.rb, line 134 def self.load_json(string) JSON.parse(string) end
# File lib/roundhouse.rb, line 142 def self.logger Roundhouse::Logging.logger end
# File lib/roundhouse.rb, line 146 def self.logger=(log) Roundhouse::Logging.logger = log end
Register a block to run at a point in the Roundhouse
lifecycle. :startup, :quiet or :shutdown are valid events.
Roundhouse.configure_server do |config| config.on(:shutdown) do puts "Goodbye cruel world!" end end
# File lib/roundhouse.rb, line 188 def self.on(event, &block) raise ArgumentError, "Symbols only please: #{event}" unless event.is_a?(Symbol) raise ArgumentError, "Invalid event name: #{event}" unless options[:lifecycle_events].key?(event) options[:lifecycle_events][event] << block end
# File lib/roundhouse.rb, line 42 def self.options @options ||= DEFAULTS.dup end
# File lib/roundhouse.rb, line 46 def self.options=(opts) @options = opts end
When set, overrides Roundhouse.options[:average_scheduled_poll_interval]
and sets the average interval that this process will delay before checking for scheduled jobs or job retries that are ready to run.
See roundhouse/scheduled.rb for an in-depth explanation of this value
# File lib/roundhouse.rb, line 155 def self.poll_interval=(interval) $stderr.puts "DEPRECATION: `config.poll_interval = #{interval}` will be removed in Roundhouse 4. Please update to `config.average_scheduled_poll_interval = #{interval}`." self.options[:poll_interval_average] = interval end
# File lib/roundhouse.rb, line 77 def self.redis raise ArgumentError, "requires a block" unless block_given? redis_pool.with do |conn| retryable = true begin yield conn rescue Redis::CommandError => ex #2550 Failover can cause the server to become a slave, need # to disconnect and reopen the socket to get back to the master. (conn.disconnect!; retryable = false; retry) if retryable && ex.message =~ /READONLY/ raise end end end
# File lib/roundhouse.rb, line 96 def self.redis=(hash) @redis = if hash.is_a?(ConnectionPool) hash else Roundhouse::RedisConnection.create(hash) end end
# File lib/roundhouse.rb, line 92 def self.redis_pool @redis ||= Roundhouse::RedisConnection.create end
Removes the generic aliases which MAY clash with names of already
created methods by other applications. The methods `roundhouse_delay`, `roundhouse_delay_for` and `roundhouse_delay_until` can be used instead.
# File lib/roundhouse/rails.rb, line 12 def self.remove_delay! # no op # This may be completely removed in the future # Those extensions make sense for Sidekiq, but do # not make sense for Roundhouse end
Resumes a queue
# File lib/roundhouse.rb, line 110 def self.resume_queue(queue_id) self.redis { |conn| Roundhouse::Monitor.resume(conn, queue_id) } end
# File lib/roundhouse.rb, line 73 def self.server? defined?(Roundhouse::CLI) end
# File lib/roundhouse.rb, line 120 def self.server_middleware @server_chain ||= Processor.default_middleware yield @server_chain if block_given? @server_chain end
Suspends a queue
# File lib/roundhouse.rb, line 105 def self.suspend_queue(queue_id) self.redis { |conn| Roundhouse::Monitor.suspend(conn, queue_id) } end
# File lib/roundhouse.rb, line 38 def self.❨╯°□°❩╯︵┻━┻ puts "Calm down, yo." end