Module: ScoutAgent::Tracked

Included in:
Agent, Assignment, Lifeline
Defined in:
lib/scout_agent/tracked.rb

Overview

A mix-in for adding status tracking to various objects. Methods are provided to set your current status and clear your status.

Instance Method Summary collapse

Instance Method Details

#clear_status(*args) ⇒ Object

:call-seq:

clear_status(name = IDCard.me && IDCard.me.process_name)

Clears any status currently set for this process. This should be called for any process setting status messages at_exit(). You can pass name explicitly if it cannot be properly determined from IDCard::me()#process_name().



56
57
58
# File 'lib/scout_agent/tracked.rb', line 56

def clear_status(*args)
  status_database.clear_status(*args) if status_database
end

#force_status_database_reloadObject

Call this to clear the cached database handle after a fork().



32
33
34
# File 'lib/scout_agent/tracked.rb', line 32

def force_status_database_reload
  @status_database = nil
end

#status(*args) ⇒ Object

:call-seq:

status(status, name = IDCard.me && IDCard.me.process_name)

Sets the status of this process. You can pass name explicitly if it cannot be properly determined from IDCard::me()#process_name().



43
44
45
# File 'lib/scout_agent/tracked.rb', line 43

def status(*args)
  status_database.update_status(*args) if status_database
end

#status_database(log = nil) ⇒ Object

Returns the status database this object this object can use to update its status.

This value is cached after the first call to speed up future interactions with the database. You’ll need to reset the cached value with a call to force_status_database_reload() after doing something that would invalidate a SQLite database handle like fork().



27
28
29
# File 'lib/scout_agent/tracked.rb', line 27

def status_database(log = nil)
  @status_database ||= Database.load(:statuses, status_log)
end

#status_logObject

Returns the log() for this object, if supported and set, or a bit bucket log object.



14
15
16
# File 'lib/scout_agent/tracked.rb', line 14

def status_log
  (respond_to?(:log) and log) or WireTap.new(nil)
end