move start all to query

This commit is contained in:
Steffen Kötte 2016-02-01 16:25:14 +01:00
parent be01b36f05
commit 0d1dbaadd7
2 changed files with 14 additions and 10 deletions

View File

@ -5,6 +5,19 @@ module Travis::API::V3
Models::Cron.where(:branch_id => repository.branches) Models::Cron.where(:branch_id => repository.branches)
end end
def start_all()
started = []
Models::Cron.all.each do |cron|
if cron.next_enqueuing <= Time.now
start(cron.branch)
started.push cron
end
end
started
end
def start(branch) def start(branch)
raise ServerError, 'repository does not have a github_id'.freeze unless branch.repository.github_id raise ServerError, 'repository does not have a github_id'.freeze unless branch.repository.github_id

View File

@ -2,16 +2,7 @@ module Travis::API::V3
class Services::Crons::Start < Service class Services::Crons::Start < Service
def run! def run!
started = [] query.start_all()
Models::Cron.all.each do |cron|
if cron.next_enqueuing <= Time.now
query.start(cron.branch)
started.push cron
end
end
started
end end
end end