Class: Resque::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/heartbeat.rb

Defined Under Namespace

Classes: Heart

Instance Method Summary collapse

Instance Method Details

#dead?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/resque/heartbeat.rb', line 37

def dead?
  return heart.dead?
end

#heartObject



25
26
27
# File 'lib/resque/heartbeat.rb', line 25

def heart
  @heart ||= Heart.new(self)
end

#is_me?Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/resque/heartbeat.rb', line 12

def is_me?
  pieces = id.split(':')
  (pieces[0].casecmp(hostname)==0) && (pieces[1].to_i == Process.pid)
end

#prune_if_deadObject



41
42
43
44
45
46
# File 'lib/resque/heartbeat.rb', line 41

def prune_if_dead
  return nil unless dead?

  Resque.logger.info "Pruning worker '#{remote_hostname}' from resque"
  unregister_worker
end

#remote_hostnameObject



29
30
31
# File 'lib/resque/heartbeat.rb', line 29

def remote_hostname
  @remote_hostname ||= id.split(':').first
end

#remote_pidObject



33
34
35
# File 'lib/resque/heartbeat.rb', line 33

def remote_pid
  @remote_pid ||= id.split(':')[1]
end

#startup_with_heartbeatObject Also known as: startup



6
7
8
9
# File 'lib/resque/heartbeat.rb', line 6

def startup_with_heartbeat
  startup_without_heartbeat
  heart.run
end

#unregister_worker_with_heartbeat(*args) ⇒ Object Also known as: unregister_worker



18
19
20
21
22
# File 'lib/resque/heartbeat.rb', line 18

def unregister_worker_with_heartbeat(*args)
  to_stop = is_me? ? heart : Heart.new(self)
  to_stop.stop
  unregister_worker_without_heartbeat(*args)
end