debian-mirror-gitlab/app/workers/pipeline_metrics_worker.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.1 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2020-04-08 14:13:33 +05:30
class PipelineMetricsWorker # rubocop:disable Scalability/IdempotentWorker
2018-03-17 18:26:18 +05:30
include ApplicationWorker
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
data_consistency :always
2021-06-08 01:23:25 +05:30
sidekiq_options retry: 3
2016-11-03 12:29:30 +05:30
include PipelineQueue
2020-04-08 14:13:33 +05:30
urgency :high
2019-12-26 22:10:19 +05:30
2016-11-03 12:29:30 +05:30
def perform(pipeline_id)
2021-12-11 22:18:48 +05:30
Ci::Pipeline.find_by_id(pipeline_id).try do |pipeline|
2016-11-03 12:29:30 +05:30
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)
2017-08-17 22:00:37 +05:30
metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: nil, pipeline_id: pipeline.id)
2016-11-03 12:29:30 +05:30
end
def update_metrics_for_succeeded_pipeline(pipeline)
2017-08-17 22:00:37 +05:30
metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at, pipeline_id: pipeline.id)
2016-11-03 12:29:30 +05:30
end
def metrics(pipeline)
2021-12-11 22:18:48 +05:30
MergeRequest::Metrics.where(merge_request_id: merge_requests(pipeline)) # rubocop: disable CodeReuse/ActiveRecord
2016-11-03 12:29:30 +05:30
end
def merge_requests(pipeline)
2019-07-07 11:18:12 +05:30
pipeline.merge_requests_as_head_pipeline.map(&:id)
2016-11-03 12:29:30 +05:30
end
end