Class: RightScale::AuditCookStub
- Includes:
- RightSupport::Ruby::EasySingleton
- Defined in:
- lib/instance/audit_cook_stub.rb
Overview
This class acts as a recipient of audit requests sent by the cook process. The audit proxy which will forward the audits to the core should be initialized before each invocation to cook
Instance Method Summary collapse
-
#close(thread_name) ⇒ Object
Reset proxy object and notify close event listener.
-
#forward_audit(kind, text, thread_name, options) ⇒ Object
Forward audit command received from cook using audit proxy.
-
#initialize ⇒ AuditCookStub
constructor
A new instance of AuditCookStub.
-
#on_close(thread_name, &blk) ⇒ Object
Register listener for when audit proxy is closed/reset Listener is executable sequence proxy to synchronize betweek cook process going away and all audits having been processed.
-
#setup_audit_forwarding(thread_name, auditor) ⇒ Object
Sets up the audit proxy that should be used to forward all audit commands.
Constructor Details
#initialize ⇒ AuditCookStub
Returns a new instance of AuditCookStub.
34 35 36 37 |
# File 'lib/instance/audit_cook_stub.rb', line 34 def initialize @auditors = {} @close_callbacks = {} end |
Instance Method Details
#close(thread_name) ⇒ Object
Reset proxy object and notify close event listener
Parameters
- thread_name(String)
-
execution thread name or default
Return
- true
-
Always return true
93 94 95 96 97 98 99 100 |
# File 'lib/instance/audit_cook_stub.rb', line 93 def close(thread_name) close_callback = @close_callbacks[thread_name] close_callback.call if close_callback true ensure @auditors[thread_name] = nil @close_callbacks[thread_name] = nil end |
#forward_audit(kind, text, thread_name, options) ⇒ Object
Forward audit command received from cook using audit proxy
Parameters
- kind(Symbol)
-
Kind of audit, one of :append_info, :append_error, :create_new_section, :update_status and :append_output
- text(String)
-
Audit content
- thread_name(String)
-
thread name for audit or default
- options
-
Optional, associated event category, one of RightScale::EventCategories
Raise
- RuntimeError
-
If audit_proxy is not set prior to calling this
59 60 61 62 63 64 65 66 67 |
# File 'lib/instance/audit_cook_stub.rb', line 59 def forward_audit(kind, text, thread_name, ) auditor = @auditors[thread_name] return unless auditor if kind == :append_output auditor.append_output(text) else auditor.__send__(kind, text, ) end end |
#on_close(thread_name, &blk) ⇒ Object
Register listener for when audit proxy is closed/reset Listener is executable sequence proxy to synchronize betweek cook process going away and all audits having been processed
Parameters
- thread_name(String)
-
execution thread name or default
Block
Given block should not take any argument and gets called back when proxy is reset
Return
- true
-
Always return true
81 82 83 84 |
# File 'lib/instance/audit_cook_stub.rb', line 81 def on_close(thread_name, &blk) @close_callbacks[thread_name] = blk true end |
#setup_audit_forwarding(thread_name, auditor) ⇒ Object
Sets up the audit proxy that should be used to forward all audit commands.
Parameters
- thread_name(String)
-
execution thread name or default
- auditor(AuditProxy)
-
audit proxy
44 45 46 47 |
# File 'lib/instance/audit_cook_stub.rb', line 44 def setup_audit_forwarding(thread_name, auditor) @auditors ||= {} @auditors[thread_name] = auditor end |