Module: Bluth::WorkerBase
- Included in:
- ScheduleWorker, Worker
- Defined in:
- lib/bluth/worker.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#current_job ⇒ Object
def rediskey(suffix=nil) self.class.rediskey index, suffix end.
- #init(h = nil, u = nil, w = nil) ⇒ Object
- #kill(force = false) ⇒ Object
-
#name ⇒ Object
Used by daemonize as the process name (linux only).
- #wid ⇒ Object
- #working!(gobid) ⇒ Object
Class Method Details
.included(obj) ⇒ Object
72 73 74 |
# File 'lib/bluth/worker.rb', line 72 def self.included(obj) obj.extend WorkerBase::ClassMethods end |
Instance Method Details
#current_job ⇒ Object
def rediskey(suffix=nil)
self.class.rediskey index, suffix
end
51 52 53 |
# File 'lib/bluth/worker.rb', line 51 def current_job Gibbler::Digest.new(@current_job || '') end |
#init(h = nil, u = nil, w = nil) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/bluth/worker.rb', line 28 def init(h=nil, u=nil, w=nil) @host, @user, @wid, = h || Bluth.sysinfo.hostname, u || Bluth.sysinfo.user, w @pid_file ||= "/tmp/#{name}.pid" @log_file ||= "/tmp/#{name}.log" @success ||= 0 @failure ||= 0 @problem ||= 0 end |
#kill(force = false) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bluth/worker.rb', line 55 def kill(force=false) if force || host == Bluth.sysinfo.hostname Familia.info "Destroying #{self.index} (this machine is: #{Bluth.sysinfo.hostname}; worker is: #{host})" Worker.kill self.pid_file if File.exists?(self.pid_file) rescue Errno::ESRCH File.delete self.log_file if File.exists?(self.log_file) destroy! else Familia.info "Worker #{self.index} not running on #{Bluth.sysinfo.hostname}" end end |
#name ⇒ Object
Used by daemonize as the process name (linux only)
43 44 45 |
# File 'lib/bluth/worker.rb', line 43 def name [self.class.prefix, wid].flatten.join '-' end |
#wid ⇒ Object
37 38 39 40 |
# File 'lib/bluth/worker.rb', line 37 def wid @wid ||= [host, user, rand, Time.now.to_f].gibbler.short @wid end |
#working!(gobid) ⇒ Object
66 67 68 69 70 |
# File 'lib/bluth/worker.rb', line 66 def working! gobid @current_job = gobid update_time save end |