2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-07 18:35:56 -04:00
|
|
|
class PipelineScheduleWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2017-05-07 18:35:56 -04:00
|
|
|
include CronjobQueue
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-05-07 18:35:56 -04:00
|
|
|
def perform
|
2017-05-10 04:04:25 -04:00
|
|
|
Ci::PipelineSchedule.active.where("next_run_at < ?", Time.now)
|
|
|
|
.preload(:owner, :project).find_each do |schedule|
|
2017-05-07 18:35:56 -04:00
|
|
|
begin
|
2017-07-05 09:55:35 -04:00
|
|
|
pipeline = Ci::CreatePipelineService.new(schedule.project,
|
|
|
|
schedule.owner,
|
|
|
|
ref: schedule.ref)
|
2017-11-15 12:55:41 -05:00
|
|
|
.execute(:schedule, ignore_skip_ci: true, save_on_errors: false, schedule: schedule)
|
2017-07-05 09:55:35 -04:00
|
|
|
|
|
|
|
schedule.deactivate! unless pipeline.persisted?
|
2017-05-07 18:35:56 -04:00
|
|
|
rescue => e
|
|
|
|
Rails.logger.error "#{schedule.id}: Failed to create a scheduled pipeline: #{e.message}"
|
|
|
|
ensure
|
|
|
|
schedule.schedule_next_run!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-05-07 18:35:56 -04:00
|
|
|
end
|