Module: Bluth::WorkerBase::ClassMethods
- Defined in:
- lib/bluth/worker.rb
Instance Method Summary collapse
- #from_redis(wid) ⇒ Object
- #kill(pid_file) ⇒ Object
- #onerror(&blk) ⇒ Object
- #onexit(&blk) ⇒ Object
- #onstart(&blk) ⇒ Object
- #reconnect!(name = nil) ⇒ Object
- #run(*args) ⇒ Object
- #run!(*args) ⇒ Object
-
#runblock(meth) ⇒ Object
A convenience method for calling onstart/onexit blocks.
Instance Method Details
#from_redis(wid) ⇒ Object
77 78 79 80 |
# File 'lib/bluth/worker.rb', line 77 def from_redis(wid) me = new nil, nil, wid super(me.index) end |
#kill(pid_file) ⇒ Object
105 106 107 108 109 |
# File 'lib/bluth/worker.rb', line 105 def kill(pid_file) self.class.runblock :onexit pid = read_pid_file pid_file super(pid_file, 10) end |
#onerror(&blk) ⇒ Object
114 115 116 117 |
# File 'lib/bluth/worker.rb', line 114 def onerror &blk @onerror = blk unless blk.nil? @onerror end |
#onexit(&blk) ⇒ Object
118 119 120 121 |
# File 'lib/bluth/worker.rb', line 118 def onexit &blk @onexit = blk unless blk.nil? @onexit end |
#onstart(&blk) ⇒ Object
110 111 112 113 |
# File 'lib/bluth/worker.rb', line 110 def onstart &blk @onstart = blk unless blk.nil? @onstart end |
#reconnect!(name = nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/bluth/worker.rb', line 81 def reconnect! name=nil Familia.info "Reconnecting #{name}" attempt = 0 success = false reconnect_tries.times { attempt += 1 Familia.info " reconnecting in #{reconnect_delay} (\##{attempt} of #{reconnect_tries})..." success = Bluth.reconnect! reconnect_delay break if success } success end |
#run(*args) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/bluth/worker.rb', line 99 def run(*args) me = new Familia.info "Created: #{me.index}" me.run me end |
#run!(*args) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/bluth/worker.rb', line 93 def run!(*args) me = new Familia.info "Created: #{me.index}" me.run! me end |
#runblock(meth) ⇒ Object
A convenience method for calling onstart/onexit blocks
123 124 125 126 127 |
# File 'lib/bluth/worker.rb', line 123 def runblock meth blk = self.send(meth) return if blk.nil? instance_eval &blk end |