2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-03 01:55:49 -05:00
|
|
|
class RunPipelineScheduleWorker
|
2017-12-08 02:58:05 -05:00
|
|
|
include ApplicationWorker
|
2017-12-03 01:55:49 -05:00
|
|
|
include PipelineQueue
|
|
|
|
|
2017-12-18 10:42:31 -05:00
|
|
|
queue_namespace :pipeline_creation
|
2017-12-03 01:55:49 -05:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-12-03 01:55:49 -05:00
|
|
|
def perform(schedule_id, user_id)
|
2017-12-06 01:24:20 -05:00
|
|
|
schedule = Ci::PipelineSchedule.find_by(id: schedule_id)
|
|
|
|
user = User.find_by(id: user_id)
|
|
|
|
|
|
|
|
return unless schedule && user
|
2017-12-03 01:55:49 -05:00
|
|
|
|
|
|
|
run_pipeline_schedule(schedule, user)
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-12-03 01:55:49 -05:00
|
|
|
|
|
|
|
def run_pipeline_schedule(schedule, user)
|
|
|
|
Ci::CreatePipelineService.new(schedule.project,
|
|
|
|
user,
|
|
|
|
ref: schedule.ref)
|
2019-05-17 08:10:44 -04:00
|
|
|
.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-07-10 15:26:47 -04:00
|
|
|
# rubocop:disable Gitlab/RailsLogger
|
2019-05-17 08:10:44 -04:00
|
|
|
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,
|
|
|
|
issue_url: 'https://gitlab.com/gitlab-org/gitlab-ce/issues/41231',
|
|
|
|
extra: { schedule_id: schedule.id })
|
|
|
|
end
|
2019-07-10 15:26:47 -04:00
|
|
|
# rubocop:enable Gitlab/RailsLogger
|
2019-05-17 08:10:44 -04:00
|
|
|
|
|
|
|
def failed_creation_counter
|
|
|
|
@failed_creation_counter ||=
|
|
|
|
Gitlab::Metrics.counter(:pipeline_schedule_creation_failed_total,
|
|
|
|
"Counter of failed attempts of pipeline schedule creation")
|
2017-12-03 01:55:49 -05:00
|
|
|
end
|
|
|
|
end
|