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

54 lines
1.7 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
class RunPipelineScheduleWorker
include ApplicationWorker
include PipelineQueue
queue_namespace :pipeline_creation
2019-12-21 20:55:43 +05:30
feature_category :continuous_integration
2018-03-17 18:26:18 +05:30
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
def perform(schedule_id, user_id)
schedule = Ci::PipelineSchedule.find_by(id: schedule_id)
user = User.find_by(id: user_id)
return unless schedule && user
run_pipeline_schedule(schedule, user)
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
def run_pipeline_schedule(schedule, user)
Ci::CreatePipelineService.new(schedule.project,
user,
ref: schedule.ref)
2019-09-04 21:01:54 +05:30
.execute!(:schedule, ignore_skip_ci: true, save_on_errors: false, schedule: schedule)
rescue Ci::CreatePipelineService::CreateError
# no-op. This is a user operation error such as corrupted .gitlab-ci.yml.
rescue => e
error(schedule, e)
end
private
2019-09-30 21:07:59 +05:30
# rubocop:disable Gitlab/RailsLogger
2019-09-04 21:01:54 +05:30
def error(schedule, error)
failed_creation_counter.increment
Rails.logger.error "Failed to create a scheduled pipeline. " \
"schedule_id: #{schedule.id} message: #{error.message}"
Gitlab::Sentry
.track_exception(error,
2019-12-04 20:38:33 +05:30
issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/41231',
2019-09-04 21:01:54 +05:30
extra: { schedule_id: schedule.id })
end
2019-09-30 21:07:59 +05:30
# rubocop:enable Gitlab/RailsLogger
2019-09-04 21:01:54 +05:30
def failed_creation_counter
@failed_creation_counter ||=
Gitlab::Metrics.counter(:pipeline_schedule_creation_failed_total,
"Counter of failed attempts of pipeline schedule creation")
2018-03-17 18:26:18 +05:30
end
end