Class: Aidp::Database::Repositories::ProgressRepository
- Inherits:
-
Aidp::Database::Repository
- Object
- Aidp::Database::Repository
- Aidp::Database::Repositories::ProgressRepository
- Defined in:
- lib/aidp/database/repositories/progress_repository.rb
Overview
Repository for progress table Replaces progress/execute.yml and progress/analyze.yml
Constant Summary collapse
- VALID_MODES =
%w[execute analyze].freeze
Instance Attribute Summary
Attributes inherited from Aidp::Database::Repository
Instance Method Summary collapse
-
#completed_steps(mode) ⇒ Array<String>
Get completed steps.
-
#current_step(mode) ⇒ String?
Get current step.
-
#get(mode) ⇒ Hash
Get progress for a mode.
-
#initialize(project_dir: Dir.pwd) ⇒ ProgressRepository
constructor
A new instance of ProgressRepository.
-
#mark_step_completed(mode, step_name) ⇒ Object
Mark step as completed.
-
#mark_step_in_progress(mode, step_name) ⇒ Object
Mark step as in progress.
-
#reset(mode) ⇒ Object
Reset progress for a mode.
-
#started_at(mode) ⇒ Time?
Get started_at timestamp.
-
#step_completed?(mode, step_name) ⇒ Boolean
Check if step is completed.
-
#upsert_progress(mode:, current_step:, steps_completed:, started_at:, updated_at:) ⇒ Object
Upsert progress data (for migrations and direct updates).
Constructor Details
#initialize(project_dir: Dir.pwd) ⇒ ProgressRepository
Returns a new instance of ProgressRepository.
13 14 15 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 13 def initialize(project_dir: Dir.pwd) super(project_dir: project_dir, table_name: "progress") end |
Instance Method Details
#completed_steps(mode) ⇒ Array<String>
Get completed steps
37 38 39 40 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 37 def completed_steps(mode) progress = get(mode) progress[:steps_completed] || [] end |
#current_step(mode) ⇒ String?
Get current step
46 47 48 49 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 46 def current_step(mode) progress = get(mode) progress[:current_step] end |
#get(mode) ⇒ Hash
Get progress for a mode
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 21 def get(mode) mode_str = mode.to_s row = query_one( "SELECT * FROM progress WHERE project_dir = ? AND mode = ?", [project_dir, mode_str] ) return empty_progress(mode_str) unless row deserialize_progress(row) end |
#mark_step_completed(mode, step_name) ⇒ Object
Mark step as completed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 64 def mark_step_completed(mode, step_name) mode_str = mode.to_s progress = get(mode) steps = progress[:steps_completed] || [] steps << step_name unless steps.include?(step_name) now = started_at = progress[:started_at] || now upsert_progress( mode: mode_str, current_step: nil, steps_completed: steps, started_at: started_at, updated_at: now ) Aidp.log_debug("progress_repository", "step_completed", mode: mode_str, step: step_name) end |
#mark_step_in_progress(mode, step_name) ⇒ Object
Mark step as in progress
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 90 def mark_step_in_progress(mode, step_name) mode_str = mode.to_s progress = get(mode) now = started_at = progress[:started_at] || now upsert_progress( mode: mode_str, current_step: step_name, steps_completed: progress[:steps_completed] || [], started_at: started_at, updated_at: now ) Aidp.log_debug("progress_repository", "step_in_progress", mode: mode_str, step: step_name) end |
#reset(mode) ⇒ Object
Reset progress for a mode
112 113 114 115 116 117 118 119 120 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 112 def reset(mode) mode_str = mode.to_s execute( "DELETE FROM progress WHERE project_dir = ? AND mode = ?", [project_dir, mode_str] ) Aidp.log_debug("progress_repository", "reset", mode: mode_str) end |
#started_at(mode) ⇒ Time?
Get started_at timestamp
126 127 128 129 130 131 132 133 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 126 def started_at(mode) progress = get(mode) return nil unless progress[:started_at] Time.parse(progress[:started_at]) rescue ArgumentError nil end |
#step_completed?(mode, step_name) ⇒ Boolean
Check if step is completed
56 57 58 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 56 def step_completed?(mode, step_name) completed_steps(mode).include?(step_name) end |
#upsert_progress(mode:, current_step:, steps_completed:, started_at:, updated_at:) ⇒ Object
Upsert progress data (for migrations and direct updates)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/aidp/database/repositories/progress_repository.rb', line 142 def upsert_progress(mode:, current_step:, steps_completed:, started_at:, updated_at:) existing = query_one( "SELECT id FROM progress WHERE project_dir = ? AND mode = ?", [project_dir, mode] ) if existing execute( <<~SQL, UPDATE progress SET current_step = ?, steps_completed = ?, started_at = ?, updated_at = ? WHERE project_dir = ? AND mode = ? SQL [ current_step, serialize_json(steps_completed), started_at, updated_at, project_dir, mode ] ) else execute( insert_sql([ :project_dir, :mode, :current_step, :steps_completed, :started_at, :updated_at ]), [ project_dir, mode, current_step, serialize_json(steps_completed), started_at, updated_at ] ) end end |