Class: Timberline
- Inherits:
-
Object
- Object
- Timberline
- Defined in:
- lib/timberline.rb,
lib/timberline/queue.rb,
lib/timberline/config.rb,
lib/timberline/worker.rb,
lib/timberline/version.rb,
lib/timberline/envelope.rb,
lib/timberline/exceptions.rb,
lib/timberline/anonymous_worker.rb
Overview
The Timberline class serves as a base namespace for Timberline libraries, but also provides some convenience methods for accessing queues and quickly and easily processing items.
Defined Under Namespace
Classes: AnonymousWorker, Config, Envelope, ItemErrored, ItemRetried, MissingContentException, Queue, Worker
Constant Summary collapse
- VERSION =
The current canonical version for Timberline.
"0.8.6"
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
-
.watch_proc ⇒ Object
Returns the value of attribute watch_proc.
Class Method Summary collapse
-
.all_queues ⇒ Array<Timberline::Queue>
A list of all non-hidden queues for this instance of Timberline.
-
.configure(&block) {|@config| ... } ⇒ Object
Method for providing custom configuration by yielding the config object.
-
.error_item(item) ⇒ Object
Convenience method to error out a queue item.
-
.log_job_results? ⇒ Boolean
Lazy-loads the Timberline configuration.
-
.max_retries ⇒ Integer
Lazy-loads the Timberline configuration.
-
.pause(queue_name) ⇒ Object
Convenience method to pause a Queue by name.
-
.push(queue_name, data, metadata = {}) ⇒ Object
Convenience method to push an item onto a queue.
-
.queue(queue_name, opts = {}) ⇒ Object
Convenience method to create a new Queue object.
-
.redis ⇒ Redis::Namespace
Obtain a reference to the redis connection that Timberline is using.
-
.redis=(server) ⇒ Object
Update the redis server that Timberline uses for its connections.
-
.retry_item(item) ⇒ Object
Convenience method to retry a queue item.
-
.stat_timeout ⇒ Integer
Lazy-loads the Timberline configuration.
-
.stat_timeout_seconds ⇒ Integer
Lazy-loads the Timberline configuration.
-
.unpause(queue_name) ⇒ Object
Convenience method to unpause a Queue by name.
-
.watch(queue_name, &block) ⇒ Object
Create and start a new AnonymousWorker with the given queue_name and block.
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
24 25 26 |
# File 'lib/timberline.rb', line 24 def config @config end |
.watch_proc ⇒ Object
Returns the value of attribute watch_proc.
25 26 27 |
# File 'lib/timberline.rb', line 25 def watch_proc @watch_proc end |
Class Method Details
.all_queues ⇒ Array<Timberline::Queue>
Returns a list of all non-hidden queues for this instance of Timberline.
72 73 74 |
# File 'lib/timberline.rb', line 72 def self.all_queues Timberline.redis.smembers("timberline_queue_names").map { |name| queue(name) } end |
.configure(&block) {|@config| ... } ⇒ Object
Method for providing custom configuration by yielding the config object. Lazy-loads the Timberline configuration.
118 119 120 121 |
# File 'lib/timberline.rb', line 118 def self.configure(&block) initialize_if_necessary yield @config end |
.error_item(item) ⇒ Object
Convenience method to error out a queue item
97 98 99 100 |
# File 'lib/timberline.rb', line 97 def self.error_item(item) origin_queue = queue(item.origin_queue) origin_queue.error_item(item) end |
.log_job_results? ⇒ Boolean
Lazy-loads the Timberline configuration.
146 147 148 149 |
# File 'lib/timberline.rb', line 146 def self.log_job_results? initialize_if_necessary @config.log_job_result_stats end |
.max_retries ⇒ Integer
Lazy-loads the Timberline configuration.
125 126 127 128 |
# File 'lib/timberline.rb', line 125 def self.max_retries initialize_if_necessary @config.max_retries end |
.pause(queue_name) ⇒ Object
Convenience method to pause a Queue by name.
104 105 106 |
# File 'lib/timberline.rb', line 104 def self.pause(queue_name) queue(queue_name).pause end |
.push(queue_name, data, metadata = {}) ⇒ Object
Convenience method to push an item onto a queue
84 85 86 |
# File 'lib/timberline.rb', line 84 def self.push(queue_name, data, ={}) queue(queue_name).push(data, ) end |
.queue(queue_name, opts = {}) ⇒ Object
Convenience method to create a new Queue object
78 79 80 |
# File 'lib/timberline.rb', line 78 def self.queue(queue_name, opts = {}) Queue.new(queue_name, opts) end |
.redis ⇒ Redis::Namespace
Obtain a reference to the redis connection that Timberline is using.
If Timberline has not already been configured, this method will initialize a new Timberline::Config first.
If a Redis connection has not yet been established, this method will establish one.
61 62 63 64 65 66 67 68 |
# File 'lib/timberline.rb', line 61 def self.redis initialize_if_necessary if @redis.nil? self.redis = Redis.new(@config.redis_config) end @redis end |
.redis=(server) ⇒ Object
Update the redis server that Timberline uses for its connections.
If Timberline has not already been configured, this method will initialize a new Timberline::Config first.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/timberline.rb', line 39 def self.redis=(server) initialize_if_necessary if server.is_a? Redis @redis = Redis::Namespace.new(@config.namespace, redis: server) elsif server.is_a? Redis::Namespace @redis = server elsif server.nil? @redis = nil else raise "Not a valid Redis connection." end end |
.retry_item(item) ⇒ Object
Convenience method to retry a queue item
90 91 92 93 |
# File 'lib/timberline.rb', line 90 def self.retry_item(item) origin_queue = queue(item.origin_queue) origin_queue.retry_item(item) end |
.stat_timeout ⇒ Integer
Lazy-loads the Timberline configuration.
132 133 134 135 |
# File 'lib/timberline.rb', line 132 def self.stat_timeout initialize_if_necessary @config.stat_timeout end |
.stat_timeout_seconds ⇒ Integer
Lazy-loads the Timberline configuration.
139 140 141 142 |
# File 'lib/timberline.rb', line 139 def self.stat_timeout_seconds initialize_if_necessary @config.stat_timeout * 60 end |
.unpause(queue_name) ⇒ Object
Convenience method to unpause a Queue by name.
110 111 112 |
# File 'lib/timberline.rb', line 110 def self.unpause(queue_name) queue(queue_name).unpause end |
.watch(queue_name, &block) ⇒ Object
Create and start a new AnonymousWorker with the given queue_name and block. Convenience method.
158 159 160 |
# File 'lib/timberline.rb', line 158 def self.watch(queue_name, &block) Timberline::AnonymousWorker.new(&block).watch(queue_name) end |