Skip to content
Snippets Groups Projects
Commit cccef5c4 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

whenever for schedules

parent 8bc8e7bc
No related branches found
No related tags found
No related merge requests found
v1.3.0
- Replace resque with sidekiq
v1.2.0
- Added Github web hook support
- Added build schedule
Loading
Loading
Loading
Loading
@@ -31,6 +31,9 @@ gem 'slim'
gem 'sinatra', :require => nil
gem 'sidekiq', '2.6.4'
 
# Scheduled
gem 'whenever', require: false
# Format dates
gem 'stamp'
 
Loading
Loading
Loading
Loading
@@ -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)
Loading
Loading
@@ -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)
Loading
Loading
@@ -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)
Loading
Loading
@@ -272,4 +274,5 @@ DEPENDENCIES
thin
uglifier (>= 1.0.3)
unicorn (~> 4.4.0)
whenever
will_paginate (~> 3.0)
1.2.0
1.3.0pre
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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'
Loading
Loading
# 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
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
Loading
Loading
@@ -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"
Loading
Loading
@@ -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|
Loading
Loading
Loading
Loading
@@ -13,6 +13,7 @@ class Runner
def perform(build_id)
@build = Build.find(build_id)
@project = @build.project
@output = ''
 
run
end
Loading
Loading
@@ -20,8 +21,6 @@ class Runner
def initialize
@logger = Logger.new(STDOUT)
@logger.level = Logger::INFO
@output = ''
end
 
def run
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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.
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment