diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-14 17:39:21 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-14 17:39:21 +0200 |
commit | cccef5c484d8da6411a73a4c576754ff83abdc1c (patch) | |
tree | 30e74e7de69729b0662411748bc18d2667c3fadf | |
parent | 8bc8e7bc5e6598262a8aba20f064b83cd7c9f0a2 (diff) | |
download | gitlab-ci-cccef5c484d8da6411a73a4c576754ff83abdc1c.tar.gz |
whenever for schedules
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | Gemfile.lock | 9 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | app/models/project.rb | 16 | ||||
-rw-r--r-- | app/views/projects/_form.html.haml | 8 | ||||
-rw-r--r-- | config/schedule.rb | 20 | ||||
-rw-r--r-- | db/migrate/20130114153451_change_schedule_invertal.rb | 9 | ||||
-rw-r--r-- | db/schema.rb | 4 | ||||
-rw-r--r-- | lib/runner.rb | 3 | ||||
-rw-r--r-- | spec/lib/runner_spec.rb | 6 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 |
12 files changed, 55 insertions, 29 deletions
@@ -1,3 +1,6 @@ +v1.3.0 + - Replace resque with sidekiq + v1.2.0 - Added Github web hook support - Added build schedule @@ -31,6 +31,9 @@ gem 'slim' gem 'sinatra', :require => nil gem 'sidekiq', '2.6.4' +# Scheduled +gem 'whenever', require: false + # Format dates gem 'stamp' diff --git a/Gemfile.lock b/Gemfile.lock index 2f6643b..24c175d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,7 @@ GEM timers (>= 1.0.0) childprocess (0.3.5) ffi (~> 1.0, >= 1.0.6) + chronic (0.9.0) coderay (1.0.8) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -111,7 +112,7 @@ GEM treetop (~> 1.4.8) method_source (0.8.1) mime-types (1.19) - multi_json (1.3.6) + multi_json (1.5.0) mysql2 (0.3.11) nokogiri (1.5.5) orm_adapter (0.4.0) @@ -225,10 +226,11 @@ GEM kgio (~> 2.6) rack raindrops (~> 0.7) - vegas (0.1.11) - rack (>= 1.0.0) warden (1.2.1) rack (>= 1.0) + whenever (0.8.2) + activesupport (>= 2.3.4) + chronic (>= 0.6.3) will_paginate (3.0.3) xpath (0.1.4) nokogiri (~> 1.3) @@ -272,4 +274,5 @@ DEPENDENCIES thin uglifier (>= 1.0.3) unicorn (~> 4.4.0) + whenever will_paginate (~> 3.0) @@ -1 +1 @@ -1.2.0 +1.3.0pre diff --git a/app/models/project.rb b/app/models/project.rb index 8384243..ed5bc2e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -13,8 +13,8 @@ class Project < ActiveRecord::Base validates_uniqueness_of :name validates :polling_interval, - format: { with: /^[1-9]\d{0,7}[m|h|d]$/ }, - if: ->(project) { project.polling_interval.present? } + presence: true, + if: ->(project) { project.always_build.present? } before_validation :set_default_values after_save :set_scheduler @@ -123,17 +123,7 @@ class Project < ActiveRecord::Base end def set_scheduler - if self.always_build && self.polling_interval.present? - Resque.set_schedule(self.schedule_id, { - :class => 'SchedulerJob', - every: self.polling_interval, - queue: 'scheduler_task', - args: [:run, self.id], - description: self.name - }) - else - Resque.remove_schedule(self.schedule_id) - end + true end def schedule_id diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 08f3616..ba482a3 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -55,12 +55,8 @@ %br .field = f.label :polling_interval, "Build interval" - = f.text_field :polling_interval, placeholder: '5h' - %ul - %li m - minutes - %li h - hours - %li d - days - %p Ex. 30m means every 30 minutes and 2d - every two days + = f.number_field :polling_interval, placeholder: '5' + %span Hours .form-actions = f.submit 'Save', class: 'btn btn-primary' = link_to 'Cancel', projects_path, class: 'btn' diff --git a/config/schedule.rb b/config/schedule.rb new file mode 100644 index 0000000..de75cf9 --- /dev/null +++ b/config/schedule.rb @@ -0,0 +1,20 @@ +# Use this file to easily define all of your cron jobs. +# +# It's helpful, but not entirely necessary to understand cron before proceeding. +# http://en.wikipedia.org/wiki/Cron + +# Example: +# +# set :output, "/path/to/my/cron_log.log" +# +# every 2.hours do +# command "/usr/bin/some_great_command" +# runner "MyModel.some_method" +# rake "some:great:rake:task" +# end +# +# every 4.days do +# runner "AnotherModel.prune_old_records" +# end + +# Learn more: http://github.com/javan/whenever diff --git a/db/migrate/20130114153451_change_schedule_invertal.rb b/db/migrate/20130114153451_change_schedule_invertal.rb new file mode 100644 index 0000000..28bc056 --- /dev/null +++ b/db/migrate/20130114153451_change_schedule_invertal.rb @@ -0,0 +1,9 @@ +class ChangeScheduleInvertal < ActiveRecord::Migration + def up + change_column :projects, :polling_interval, :integer, null: true + end + + def down + change_column :projects, :polling_interval, :string, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 2caae38..a03284f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20121224092350) do +ActiveRecord::Schema.define(:version => 20130114153451) do create_table "builds", :force => true do |t| t.integer "project_id" @@ -38,7 +38,7 @@ ActiveRecord::Schema.define(:version => 20121224092350) do t.string "default_ref" t.string "gitlab_url" t.boolean "always_build", :default => true - t.string "polling_interval" + t.integer "polling_interval" end create_table "users", :force => true do |t| diff --git a/lib/runner.rb b/lib/runner.rb index 530ee3c..112d40a 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -13,6 +13,7 @@ class Runner def perform(build_id) @build = Build.find(build_id) @project = @build.project + @output = '' run end @@ -20,8 +21,6 @@ class Runner def initialize @logger = Logger.new(STDOUT) @logger.level = Logger::INFO - - @output = '' end def run diff --git a/spec/lib/runner_spec.rb b/spec/lib/runner_spec.rb index db13a73..b46aaff 100644 --- a/spec/lib/runner_spec.rb +++ b/spec/lib/runner_spec.rb @@ -6,16 +6,18 @@ describe Runner do it "should run a success build" do build = setup_build 'ls' - Runner.new(build).run + Runner.new.perform(build.id) + build.reload build.trace.should include 'six.gemspec' build.should be_success end it "should run a failed build" do build = setup_build 'cat MISSING' - Runner.new(build).run + Runner.new.perform(build.id) + build.reload build.should be_failed end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0f235cf..b93f0a6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,7 @@ ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' +require 'sidekiq/testing/inline' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. |