From 0d1dbaadd7357871c690d352c03b160150ae0592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Ko=CC=88tte?= Date: Mon, 1 Feb 2016 16:25:14 +0100 Subject: [PATCH] move start all to query --- lib/travis/api/v3/queries/crons.rb | 13 +++++++++++++ lib/travis/api/v3/services/crons/start.rb | 11 +---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/travis/api/v3/queries/crons.rb b/lib/travis/api/v3/queries/crons.rb index 9998097e..761da836 100644 --- a/lib/travis/api/v3/queries/crons.rb +++ b/lib/travis/api/v3/queries/crons.rb @@ -5,6 +5,19 @@ module Travis::API::V3 Models::Cron.where(:branch_id => repository.branches) 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) raise ServerError, 'repository does not have a github_id'.freeze unless branch.repository.github_id diff --git a/lib/travis/api/v3/services/crons/start.rb b/lib/travis/api/v3/services/crons/start.rb index 1bef2f79..104d43f5 100644 --- a/lib/travis/api/v3/services/crons/start.rb +++ b/lib/travis/api/v3/services/crons/start.rb @@ -2,16 +2,7 @@ module Travis::API::V3 class Services::Crons::Start < Service def run! - started = [] - - Models::Cron.all.each do |cron| - if cron.next_enqueuing <= Time.now - query.start(cron.branch) - started.push cron - end - end - - started + query.start_all() end end