Module: Roundhouse
- Defined in:
- lib/roundhouse.rb,
lib/roundhouse/api.rb,
lib/roundhouse/cli.rb,
lib/roundhouse/web.rb,
lib/roundhouse/util.rb,
lib/roundhouse/actor.rb,
lib/roundhouse/fetch.rb,
lib/roundhouse/rails.rb,
lib/roundhouse/client.rb,
lib/roundhouse/script.rb,
lib/roundhouse/worker.rb,
lib/roundhouse/logging.rb,
lib/roundhouse/manager.rb,
lib/roundhouse/monitor.rb,
lib/roundhouse/testing.rb,
lib/roundhouse/version.rb,
lib/roundhouse/launcher.rb,
lib/roundhouse/paginator.rb,
lib/roundhouse/processor.rb,
lib/roundhouse/scheduled.rb,
lib/roundhouse/web_helpers.rb,
lib/roundhouse/middleware/chain.rb,
lib/roundhouse/redis_connection.rb,
lib/roundhouse/exception_handler.rb,
lib/roundhouse/middleware/server/logging.rb,
lib/generators/roundhouse/worker_generator.rb,
lib/roundhouse/middleware/server/retry_jobs.rb,
lib/roundhouse/middleware/server/active_record.rb
Defined Under Namespace
Modules: Actor, ExceptionHandler, Generators, Logging, Middleware, Paginator, Scheduled, Util, WebHelpers, Worker
Classes: CLI, Client, DeadSet, EmptyQueueError, Fetcher, Job, JobSet, Launcher, Manager, Monitor, Process, ProcessSet, Processor, Queue, RedisConnection, RetrySet, RoundRobinFetch, ScheduledSet, Script, Shutdown, SortedEntry, SortedSet, Stats, Testing, Web, Workers
Constant Summary
collapse
- NAME =
'Roundhouse'
- LICENSE =
'See LICENSE and the LGPL-3.0 for licensing details.'
- DEFAULTS =
{
labels: [],
concurrency: 25,
require: '.',
environment: nil,
timeout: 8,
poll_interval_average: nil,
average_scheduled_poll_interval: 15,
error_handlers: [],
lifecycle_events: {
startup: [],
quiet: [],
shutdown: [],
},
dead_max_jobs: 10_000,
dead_timeout_in_seconds: 180 * 24 * 60 * 60
}
- DEFAULT_WORKER_OPTIONS =
{
'retry' => true
}
- VERSION =
"0.3.1"
Class Method Summary
collapse
Class Method Details
.average_scheduled_poll_interval=(interval) ⇒ Object
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
165
166
167
|
# File 'lib/roundhouse.rb', line 165
def self.average_scheduled_poll_interval=(interval)
self.options[:average_scheduled_poll_interval] = interval
end
|
.client_middleware {|@client_chain| ... } ⇒ Object
114
115
116
117
118
|
# 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
69
70
71
|
# 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
59
60
61
|
# File 'lib/roundhouse.rb', line 59
def self.configure_server
yield self if server?
end
|
.default_worker_options ⇒ Object
130
131
132
|
# File 'lib/roundhouse.rb', line 130
def self.default_worker_options
defined?(@default_worker_options) ? @default_worker_options : DEFAULT_WORKER_OPTIONS
end
|
.default_worker_options=(hash) ⇒ Object
126
127
128
|
# File 'lib/roundhouse.rb', line 126
def self.default_worker_options=(hash)
@default_worker_options = default_worker_options.merge(hash.stringify_keys)
end
|
.dump_json(object) ⇒ Object
138
139
140
|
# File 'lib/roundhouse.rb', line 138
def self.dump_json(object)
JSON.generate(object)
end
|
.error_handlers ⇒ Object
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.
176
177
178
|
# File 'lib/roundhouse.rb', line 176
def self.error_handlers
self.options[:error_handlers]
end
|
.hook_rails! ⇒ Object
2
3
4
5
6
7
|
# File 'lib/roundhouse/rails.rb', line 2
def self.hook_rails!
end
|
.load_json(string) ⇒ Object
134
135
136
|
# File 'lib/roundhouse.rb', line 134
def self.load_json(string)
JSON.parse(string)
end
|
.logger ⇒ Object
142
143
144
|
# File 'lib/roundhouse.rb', line 142
def self.logger
Roundhouse::Logging.logger
end
|
.logger=(log) ⇒ Object
146
147
148
|
# File 'lib/roundhouse.rb', line 146
def self.logger=(log)
Roundhouse::Logging.logger = log
end
|
.on(event, &block) ⇒ Object
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
188
189
190
191
192
|
# 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
|
.options ⇒ Object
42
43
44
|
# File 'lib/roundhouse.rb', line 42
def self.options
@options ||= DEFAULTS.dup
end
|
.options=(opts) ⇒ Object
46
47
48
|
# File 'lib/roundhouse.rb', line 46
def self.options=(opts)
@options = opts
end
|
.poll_interval=(interval) ⇒ Object
When set, overrides Roundhouse.options 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
155
156
157
158
|
# 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
|
.redis ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# 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
(conn.disconnect!; retryable = false; retry) if retryable && ex.message =~ /READONLY/
raise
end
end
end
|
.redis=(hash) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/roundhouse.rb', line 96
def self.redis=(hash)
@redis = if hash.is_a?(ConnectionPool)
hash
else
Roundhouse::RedisConnection.create(hash)
end
end
|
.redis_pool ⇒ Object
92
93
94
|
# File 'lib/roundhouse.rb', line 92
def self.redis_pool
@redis ||= Roundhouse::RedisConnection.create
end
|
.remove_delay! ⇒ Object
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.
12
13
14
15
16
17
|
# File 'lib/roundhouse/rails.rb', line 12
def self.remove_delay!
end
|
.resume_queue(queue_id) ⇒ Object
110
111
112
|
# File 'lib/roundhouse.rb', line 110
def self.resume_queue(queue_id)
self.redis { |conn| Roundhouse::Monitor.resume(conn, queue_id) }
end
|
.server? ⇒ Boolean
73
74
75
|
# File 'lib/roundhouse.rb', line 73
def self.server?
defined?(Roundhouse::CLI)
end
|
.server_middleware {|@server_chain| ... } ⇒ Object
120
121
122
123
124
|
# File 'lib/roundhouse.rb', line 120
def self.server_middleware
@server_chain ||= Processor.default_middleware
yield @server_chain if block_given?
@server_chain
end
|
.suspend_queue(queue_id) ⇒ Object
105
106
107
|
# File 'lib/roundhouse.rb', line 105
def self.suspend_queue(queue_id)
self.redis { |conn| Roundhouse::Monitor.suspend(conn, queue_id) }
end
|
.❨╯°□°❩╯︵┻━┻ ⇒ Object
38
39
40
|
# File 'lib/roundhouse.rb', line 38
def self.
|