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