Class: RosettAi::Workflow::AuditLog
- Inherits:
-
Object
- Object
- RosettAi::Workflow::AuditLog
- Defined in:
- lib/rosett_ai/workflow/audit_log.rb
Overview
Structured audit log for workflow execution.
Records each step execution with timestamp, status, and duration. Supports resume by identifying completed steps from the log.
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
-
#completed_steps(workflow_name) ⇒ Array<String>
Returns step names that completed successfully for a workflow.
-
#initialize(log_path: nil) ⇒ AuditLog
constructor
A new instance of AuditLog.
-
#record(workflow_name:, step_name:, status:, duration_ms: 0.0, details: nil) ⇒ Object
Records a step execution result.
-
#to_h ⇒ Hash
Serializable summary.
Constructor Details
#initialize(log_path: nil) ⇒ AuditLog
Returns a new instance of AuditLog.
21 22 23 24 |
# File 'lib/rosett_ai/workflow/audit_log.rb', line 21 def initialize(log_path: nil) @log_path = log_path @entries = load_entries end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
18 19 20 |
# File 'lib/rosett_ai/workflow/audit_log.rb', line 18 def entries @entries end |
Instance Method Details
#completed_steps(workflow_name) ⇒ Array<String>
Returns step names that completed successfully for a workflow.
50 51 52 53 54 |
# File 'lib/rosett_ai/workflow/audit_log.rb', line 50 def completed_steps(workflow_name) @entries .select { |e| e['workflow'] == workflow_name && e['status'] == 'pass' } .map { |e| e['step'] } end |
#record(workflow_name:, step_name:, status:, duration_ms: 0.0, details: nil) ⇒ Object
Records a step execution result.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rosett_ai/workflow/audit_log.rb', line 33 def record(workflow_name:, step_name:, status:, duration_ms: 0.0, details: nil) entry = { 'workflow' => workflow_name, 'step' => step_name, 'status' => status, 'timestamp' => Time.now.utc.iso8601, 'duration_ms' => duration_ms.round(1) } entry['details'] = details if details @entries << entry persist_entry(entry) end |
#to_h ⇒ Hash
Returns serializable summary.
57 58 59 60 61 62 63 64 |
# File 'lib/rosett_ai/workflow/audit_log.rb', line 57 def to_h { 'entries' => @entries, 'total' => @entries.size, 'pass' => @entries.count { |e| e['status'] == 'pass' }, 'fail' => @entries.count { |e| e['status'] == 'fail' } } end |