Module: FunCi::Persistence::PipelineRun
- Defined in:
- lib/fun_ci/persistence/pipeline_run.rb
Class Method Summary collapse
- .create(db, commit_hash:, branch:, project_path: nil) ⇒ Object
- .find(db, id) ⇒ Object
- .find_by_branch(db, branch) ⇒ Object
- .find_by_commit(db, commit_hash) ⇒ Object
- .find_running_with_pid(db, branch) ⇒ Object
- .recent(db, limit: 20) ⇒ Object
- .store_pid(db, id, pid) ⇒ Object
- .update_status(db, id, new_status) ⇒ Object
Class Method Details
.create(db, commit_hash:, branch:, project_path: nil) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/fun_ci/persistence/pipeline_run.rb', line 8 def self.create(db, commit_hash:, branch:, project_path: nil) now = Time.now.utc.iso8601 db.execute( "INSERT INTO pipeline_runs (commit_hash, branch, project_path, status, created_at, updated_at) VALUES (?, ?, ?, 'scheduled', ?, ?)", [commit_hash, branch, project_path, now, now] ) db.last_insert_row_id end |
.find(db, id) ⇒ Object
17 18 19 20 21 |
# File 'lib/fun_ci/persistence/pipeline_run.rb', line 17 def self.find(db, id) row = db.execute("SELECT id, commit_hash, branch, status, pid, project_path, created_at, updated_at FROM pipeline_runs WHERE id = ?", [id]).first return nil unless row row_to_hash(row) end |
.find_by_branch(db, branch) ⇒ Object
23 24 25 26 |
# File 'lib/fun_ci/persistence/pipeline_run.rb', line 23 def self.find_by_branch(db, branch) rows = db.execute("SELECT id, commit_hash, branch, status, pid, project_path, created_at, updated_at FROM pipeline_runs WHERE branch = ? ORDER BY id DESC", [branch]) rows.map { |row| row_to_hash(row) } end |
.find_by_commit(db, commit_hash) ⇒ Object
28 29 30 31 |
# File 'lib/fun_ci/persistence/pipeline_run.rb', line 28 def self.find_by_commit(db, commit_hash) rows = db.execute("SELECT id, commit_hash, branch, status, pid, project_path, created_at, updated_at FROM pipeline_runs WHERE commit_hash = ? ORDER BY id DESC", [commit_hash]) rows.map { |row| row_to_hash(row) } end |
.find_running_with_pid(db, branch) ⇒ Object
37 38 39 40 41 |
# File 'lib/fun_ci/persistence/pipeline_run.rb', line 37 def self.find_running_with_pid(db, branch) row = db.execute("SELECT id, commit_hash, branch, status, pid, project_path, created_at, updated_at FROM pipeline_runs WHERE branch = ? AND status = 'running' AND pid IS NOT NULL ORDER BY id DESC LIMIT 1", [branch]).first return nil unless row row_to_hash(row) end |
.recent(db, limit: 20) ⇒ Object
48 49 50 51 |
# File 'lib/fun_ci/persistence/pipeline_run.rb', line 48 def self.recent(db, limit: 20) rows = db.execute("SELECT id, commit_hash, branch, status, pid, project_path, created_at, updated_at FROM pipeline_runs ORDER BY id DESC LIMIT ?", [limit]) rows.map { |row| row_to_hash(row) } end |
.store_pid(db, id, pid) ⇒ Object
33 34 35 |
# File 'lib/fun_ci/persistence/pipeline_run.rb', line 33 def self.store_pid(db, id, pid) db.execute("UPDATE pipeline_runs SET pid = ? WHERE id = ?", [pid, id]) end |
.update_status(db, id, new_status) ⇒ Object
43 44 45 46 |
# File 'lib/fun_ci/persistence/pipeline_run.rb', line 43 def self.update_status(db, id, new_status) now = Time.now.utc.iso8601 db.execute("UPDATE pipeline_runs SET status = ?, updated_at = ? WHERE id = ?", [new_status, now, id]) end |