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

Polising after schedule

parent 874a71ec
No related branches found
No related tags found
No related merge requests found
web: bundle exec rails s -p $PORT
worker: bundle exec rake environment resque:work QUEUE=runner VVERBOSE=1
worker: bundle exec rake environment resque:work QUEUE=runner,scheduler_task VVERBOSE=1
schedule: bundle exec rake environment resque:scheduler VVERBOSE=1 RAILS_ENV=development
class Project < ActiveRecord::Base
attr_accessible :name, :path, :scripts, :timeout, :token, :default_ref, :gitlab_url, :always_build, :polling_interval
validates_presence_of :name, :path, :scripts, :timeout, :token, :default_ref
validates :polling_interval, :format => { :with => /^[1-9]\d{0,7}[s|m|d]$/ }, :unless => Proc.new{|project| project.polling_interval.blank?}
attr_accessible :name, :path, :scripts, :timeout, :token,
:default_ref, :gitlab_url, :always_build, :polling_interval
 
has_many :builds, dependent: :destroy
 
validate :repo_present?
 
#
# Validations
#
validates_presence_of :name, :path, :scripts, :timeout, :token, :default_ref
validate :repo_present?
validates_uniqueness_of :name
 
validates :polling_interval,
format: { with: /^[1-9]\d{0,7}[s|m|d]$/ },
if: ->(project) { project.polling_interval.present? }
before_validation :set_default_values
after_save :set_scheduler
 
Loading
Loading
@@ -119,17 +124,21 @@ class Project < ActiveRecord::Base
 
def set_scheduler
if self.polling_interval.present?
Resque.set_schedule(self.token, {
Resque.set_schedule(self.schedule_id, {
:class => 'SchedulerJob',
:every => self.polling_interval,
:queue => 'scheduler_task',
:args => [:run, self.id],
:description => self.name
every: self.polling_interval,
queue: 'scheduler_task',
args: [:run, self.id],
description: self.name
})
else
Resque.remove_schedule(self.token)
Resque.remove_schedule(self.schedule_id)
end
end
def schedule_id
"project-#{id}"
end
end
 
 
Loading
Loading
Loading
Loading
@@ -17,12 +17,6 @@
.field
= f.label :token, "Token (Leave empty to generate random token)"
= f.text_field :token, class: 'input-xlarge', placeholder: 'xEeFCaDAB89'
.field
= f.label :always_build, "Always_build"
= f.check_box :always_build
.field
= f.label :polling_interval, "Polling_interval"
= f.text_field :polling_interval
 
%fieldset
%legend Git
Loading
Loading
@@ -49,8 +43,20 @@
= f.number_field :timeout, class: 'input-xlarge'
.field
= f.label :scripts
= f.text_area :scripts, class: 'input-xxlarge', rows: 18, placeholder: "bundle exec rake spec"
= f.text_area :scripts, class: 'input-xxlarge', rows: 11, placeholder: "bundle exec rake spec"
 
%fieldset
%legend Build Schedule
.field
= f.label :always_build do
= f.check_box :always_build
%span Enable automatic build on schedule
%br
.field
= f.label :polling_interval, "Build interval"
= f.text_field :polling_interval, placeholder: '30m'
%small Ex. 30m means every 30 minutes and 2d - every two days
.form-actions
= f.submit 'Save', class: 'btn btn-primary'
= link_to 'Cancel', projects_path, class: 'btn'
Loading
Loading
require Rails.root.join('lib', 'runner')
#require Rails.root.join('lib', 'scheduler_job')
require 'scheduler_job'
 
# Custom Redis configuration
Loading
Loading
class AddScheduleToProjects < ActiveRecord::Migration
def change
add_column :projects, :always_build, :boolean, :default => true
add_column :projects, :polling_interval, :string
add_column :projects, :always_build, :boolean, default: false, null: false
add_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 => 20121116144312) do
ActiveRecord::Schema.define(:version => 20121224092350) do
 
create_table "builds", :force => true do |t|
t.integer "project_id"
Loading
Loading
@@ -28,15 +28,17 @@ ActiveRecord::Schema.define(:version => 20121116144312) do
end
 
create_table "projects", :force => true do |t|
t.string "name", :null => false
t.string "path", :null => false
t.integer "timeout", :default => 1800, :null => false
t.text "scripts", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "name", :null => false
t.string "path", :null => false
t.integer "timeout", :default => 1800, :null => false
t.text "scripts", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "token"
t.string "default_ref"
t.string "gitlab_url"
t.boolean "always_build", :default => true
t.string "polling_interval"
end
 
create_table "users", :force => true do |t|
Loading
Loading
Loading
Loading
@@ -5,8 +5,6 @@ namespace :resque do
task :setup => :environment do
require 'resque'
require 'resque_scheduler'
#require 'resque_scheduler/server'
#require 'resque/scheduler'
 
# you probably already have this somewhere
#Resque.redis = 'localhost:6379'
Loading
Loading
Loading
Loading
@@ -26,13 +26,13 @@ describe Project do
it 'should not set schedule if polling_interval is blank' do
project = FactoryGirl.create :project
project.update_attribute(:polling_interval, nil)
Resque.get_schedule(project.token).should be_nil
Resque.get_schedule(project.schedule_id).should be_nil
end
 
it 'should set schedule if polling_interval is set' do
project = FactoryGirl.create :project
project.update_attribute(:polling_interval, '3m')
Resque.get_schedule(project.token).should.to_s == {
Resque.get_schedule(project.schedule_id).should.to_s == {
:class => 'SchedulerJob',
:every => project.polling_interval,
:args => [:run, project.id],
Loading
Loading
@@ -43,9 +43,9 @@ describe Project do
it 'should cancel schedule if clear polling_interval' do
project = FactoryGirl.create :project
project.update_attribute(:polling_interval, '3m')
Resque.get_schedule(project.token).should_not be_nil
Resque.get_schedule(project.schedule_id).should_not be_nil
project.update_attribute(:polling_interval, nil)
Resque.get_schedule(project.token).should be_nil
Resque.get_schedule(project.schedule_id).should be_nil
end
end
 
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