diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-10-17 10:55:47 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-10-17 11:27:53 +0300 |
commit | a497803072edb4c8edbf9f4daf3832c122ee50e2 (patch) | |
tree | 2d0cf4e115f0e5f76015ff0ee1091f1788e4a519 /app/workers/pipeline_metrics_worker.rb | |
parent | 9c6c5c79f8d3a555ded0539e06a922bc058d5c20 (diff) |
Improve spec for pipeline metrics worker
Diffstat (limited to 'app/workers/pipeline_metrics_worker.rb')
-rw-r--r-- | app/workers/pipeline_metrics_worker.rb | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/app/workers/pipeline_metrics_worker.rb b/app/workers/pipeline_metrics_worker.rb index 3d1cd770515..7bb92df3bbd 100644 --- a/app/workers/pipeline_metrics_worker.rb +++ b/app/workers/pipeline_metrics_worker.rb @@ -5,11 +5,26 @@ class PipelineMetricsWorker def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| - merge_requests = pipeline.merge_requests.map(&:id) - - metrics = MergeRequest::Metrics.where(merge_request_id: merge_requests) - metrics.update_all(latest_build_started_at: pipeline.started_at) if pipeline.active? - metrics.update_all(latest_build_finished_at: pipeline.finished_at) if pipeline.success? + update_metrics_for_active_pipeline(pipeline) if pipeline.active? + update_metrics_for_succeeded_pipeline(pipeline) if pipeline.success? end end + + private + + def update_metrics_for_active_pipeline(pipeline) + metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: nil) + end + + def update_metrics_for_succeeded_pipeline(pipeline) + metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at) + end + + def metrics(pipeline) + MergeRequest::Metrics.where(merge_request_id: merge_requests(pipeline)) + end + + def merge_requests(pipeline) + pipeline.merge_requests.map(&:id) + end end |