Class: FunCi::Persistence::DbRecorder
- Inherits:
-
Object
- Object
- FunCi::Persistence::DbRecorder
- Defined in:
- lib/fun_ci/persistence/pipeline_recorder.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#db_path ⇒ Object
readonly
Returns the value of attribute db_path.
-
#pipeline_run_id ⇒ Object
readonly
Returns the value of attribute pipeline_run_id.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #complete_run ⇒ Object
- #create_run(commit_hash:, branch:, project_path: nil) ⇒ Object
- #end_stage(job_id, status) ⇒ Object
- #fail_run ⇒ Object
-
#initialize(db, pipeline_run_id: nil) ⇒ DbRecorder
constructor
A new instance of DbRecorder.
- #start_stage(stage) ⇒ Object
Constructor Details
#initialize(db, pipeline_run_id: nil) ⇒ DbRecorder
Returns a new instance of DbRecorder.
28 29 30 31 32 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 28 def initialize(db, pipeline_run_id: nil) @db = db @db_path = db.filename("main") @pipeline_run_id = pipeline_run_id end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
21 22 23 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 21 def db @db end |
#db_path ⇒ Object (readonly)
Returns the value of attribute db_path.
21 22 23 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 21 def db_path @db_path end |
#pipeline_run_id ⇒ Object (readonly)
Returns the value of attribute pipeline_run_id.
21 22 23 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 21 def pipeline_run_id @pipeline_run_id end |
Class Method Details
.for_background(db_path, pipeline_run_id) ⇒ Object
23 24 25 26 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 23 def self.for_background(db_path, pipeline_run_id) db = Database.connection(db_path) new(db, pipeline_run_id: pipeline_run_id) end |
Instance Method Details
#close ⇒ Object
34 35 36 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 34 def close @db.close rescue nil end |
#complete_run ⇒ Object
55 56 57 58 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 55 def complete_run return unless @pipeline_run_id PipelineRun.update_status(@db, @pipeline_run_id, "completed") end |
#create_run(commit_hash:, branch:, project_path: nil) ⇒ Object
38 39 40 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 38 def create_run(commit_hash:, branch:, project_path: nil) @pipeline_run_id = PipelineRun.create(@db, commit_hash: commit_hash, branch: branch, project_path: project_path) end |
#end_stage(job_id, status) ⇒ Object
50 51 52 53 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 50 def end_stage(job_id, status) return unless job_id StageJob.update_status(@db, job_id, status) end |
#fail_run ⇒ Object
60 61 62 63 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 60 def fail_run return unless @pipeline_run_id PipelineRun.update_status(@db, @pipeline_run_id, "failed") end |
#start_stage(stage) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/fun_ci/persistence/pipeline_recorder.rb', line 42 def start_stage(stage) return nil unless @pipeline_run_id ensure_running job_id = StageJob.create(@db, pipeline_run_id: @pipeline_run_id, stage: stage) StageJob.update_status(@db, job_id, "running") job_id end |