2017-08-17 22:00:37 +05:30
|
|
|
class PipelineScheduleWorker
|
2018-03-17 18:26:18 +05:30
|
|
|
include ApplicationWorker
|
2017-08-17 22:00:37 +05:30
|
|
|
include CronjobQueue
|
|
|
|
|
|
|
|
def perform
|
2017-09-10 17:25:29 +05:30
|
|
|
Ci::PipelineSchedule.active.where("next_run_at < ?", Time.now)
|
|
|
|
.preload(:owner, :project).find_each do |schedule|
|
2017-08-17 22:00:37 +05:30
|
|
|
begin
|
2017-09-10 17:25:29 +05:30
|
|
|
pipeline = Ci::CreatePipelineService.new(schedule.project,
|
|
|
|
schedule.owner,
|
|
|
|
ref: schedule.ref)
|
2018-03-17 18:26:18 +05:30
|
|
|
.execute(:schedule, ignore_skip_ci: true, save_on_errors: false, schedule: schedule)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
schedule.deactivate! unless pipeline.persisted?
|
2017-08-17 22:00:37 +05:30
|
|
|
rescue => e
|
|
|
|
Rails.logger.error "#{schedule.id}: Failed to create a scheduled pipeline: #{e.message}"
|
|
|
|
ensure
|
|
|
|
schedule.schedule_next_run!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|