Module: Bluth
- Defined in:
- lib/bluth.rb,
lib/bluth.rb,
lib/bluth.rb,
lib/bluth.rb,
lib/bluth/cli.rb,
lib/bluth/timingbelt.rb,
lib/bluth/worker.rb
Defined Under Namespace
Modules: Handler, Queue, TimingBelt, VERSION, WorkerBase Classes: Buster, CLI, Gob, Maeby, ScheduleWorker, Shutdown, Worker
Class Attribute Summary collapse
-
.conf ⇒ Object
readonly
Returns the value of attribute conf.
-
.db ⇒ Object
readonly
Returns the value of attribute db.
-
.env ⇒ Object
Returns the value of attribute env.
-
.handlers ⇒ Object
readonly
Returns the value of attribute handlers.
-
.locks ⇒ Object
readonly
Returns the value of attribute locks.
-
.priority ⇒ Object
Returns the value of attribute priority.
-
.queuetimeout ⇒ Object
Returns the value of attribute queuetimeout.
-
.redis ⇒ Object
Returns the value of attribute redis.
-
.salt ⇒ Object
readonly
Returns the value of attribute salt.
-
.scheduler ⇒ Object
Returns the value of attribute scheduler.
-
.uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
- .clear_locks ⇒ Object
- .connect ⇒ Object
- .find_locks ⇒ Object
-
.onconnect(&blk) ⇒ Object
A block to be called before a worker starts.
- .pop ⇒ Object
- .queue(n) ⇒ Object
- .queue?(n) ⇒ Boolean
- .reconnect!(delay = 5) ⇒ Object
-
.shift ⇒ Object
Workers use a blocking pop and will wait for up to Bluth.queuetimeout (seconds) before returnning nil.
- .sysinfo ⇒ Object
Class Attribute Details
.conf ⇒ Object (readonly)
Returns the value of attribute conf.
45 46 47 |
# File 'lib/bluth.rb', line 45 def conf @conf end |
.db ⇒ Object (readonly)
Returns the value of attribute db.
45 46 47 |
# File 'lib/bluth.rb', line 45 def db @db end |
.env ⇒ Object
Returns the value of attribute env.
46 47 48 |
# File 'lib/bluth.rb', line 46 def env @env end |
.handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
45 46 47 |
# File 'lib/bluth.rb', line 45 def handlers @handlers end |
.locks ⇒ Object (readonly)
Returns the value of attribute locks.
45 46 47 |
# File 'lib/bluth.rb', line 45 def locks @locks end |
.priority ⇒ Object
Returns the value of attribute priority.
46 47 48 |
# File 'lib/bluth.rb', line 46 def priority @priority end |
.queuetimeout ⇒ Object
Returns the value of attribute queuetimeout.
46 47 48 |
# File 'lib/bluth.rb', line 46 def queuetimeout @queuetimeout end |
.redis ⇒ Object
Returns the value of attribute redis.
46 47 48 |
# File 'lib/bluth.rb', line 46 def redis @redis end |
.salt ⇒ Object (readonly)
Returns the value of attribute salt.
23 24 25 |
# File 'lib/bluth/worker.rb', line 23 def salt @salt end |
.scheduler ⇒ Object
Returns the value of attribute scheduler.
46 47 48 |
# File 'lib/bluth.rb', line 46 def scheduler @scheduler end |
.uri ⇒ Object
Returns the value of attribute uri.
46 47 48 |
# File 'lib/bluth.rb', line 46 def uri @uri end |
Class Method Details
.clear_locks ⇒ Object
83 84 85 86 87 88 |
# File 'lib/bluth.rb', line 83 def Bluth.clear_locks @locks.each { |lock| Familia.info "Removing lock #{lock}" Bluth.redis.del lock } end |
.connect ⇒ Object
66 67 68 |
# File 'lib/bluth.rb', line 66 def connect instance_eval &onconnect unless onconnect.nil? end |
.find_locks ⇒ Object
89 90 91 |
# File 'lib/bluth.rb', line 89 def Bluth.find_locks @locks = Bluth.redis.keys(Familia.rediskey('*', :lock)) end |
.onconnect(&blk) ⇒ Object
A block to be called before a worker starts.
e.g.
Bluth.onconnect do
config = YourProject.load_config
Familia.uri = config[:redis_uri]
end
Note: this block can be called multiple times so do not put anything with side effects in here.
62 63 64 65 |
# File 'lib/bluth.rb', line 62 def onconnect &blk @onconnect = blk unless blk.nil? @onconnect end |
.pop ⇒ Object
166 167 168 |
# File 'lib/bluth.rb', line 166 def Bluth.pop blocking_queue_handler :brpop end |
.queue(n) ⇒ Object
96 97 98 99 |
# File 'lib/bluth.rb', line 96 def Bluth.queue(n) raise ArgumentError, "No such queue: #{n}" unless queue?(n) Bluth::Queue.send n end |
.queue?(n) ⇒ Boolean
93 94 95 |
# File 'lib/bluth.rb', line 93 def Bluth.queue?(n) Bluth::Queue.queues.collect(&:name).member?(n.to_s.to_sym) end |
.reconnect!(delay = 5) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bluth.rb', line 69 def reconnect! delay=5 sleep delay success = begin Familia.reconnect_all! (Bluth::Gob.redis.ping.to_s.upcase == 'PONG') rescue => ex Familia.info " #{ex.}" false end Familia.info " reconnected: #{success}" success end |
.shift ⇒ Object
Workers use a blocking pop and will wait for up to Bluth.queuetimeout (seconds) before returnning nil. Note that the queues are still processed in order. If all queues are empty, the first one to return a value is use. See:
162 163 164 |
# File 'lib/bluth.rb', line 162 def Bluth.shift blocking_queue_handler :blpop end |
.sysinfo ⇒ Object
47 48 49 50 |
# File 'lib/bluth.rb', line 47 def sysinfo @sysinfo ||= SysInfo.new.freeze @sysinfo end |