[refs #505] Merge master into 505-state_machine_migrate

This commit is contained in:
konstantin.grabar 2012-06-19 13:43:38 +04:00
commit dc8a11fa68
24 changed files with 210 additions and 224 deletions

28
Gemfile
View File

@ -1,6 +1,6 @@
source 'http://rubygems.org'
gem 'rails', '3.2.3' #, :git => 'git://github.com/rails/rails.git'
gem 'rails', '3.2.6' #, :git => 'git://github.com/rails/rails.git'
gem 'pg', '~> 0.13.2'
# gem 'silent-postgres', :git => 'git://github.com/dolzenko/silent-postgres.git' #'~> 0.1.1'
@ -12,16 +12,16 @@ gem 'omniauth', '~> 1.0.3'
gem 'omniauth-openid', '~> 1.0.1'
gem 'cancan', '~> 1.6.7'
gem 'ancestry', '~> 1.2.5'
gem 'paperclip', '~> 3.0.2'
#gem 'delayed_job_active_record', '~> 0.3.2'
gem 'resque'
gem 'ancestry', '~> 1.3.0'
gem 'paperclip', '~> 3.0.4'
gem 'resque', '~> 1.20.0'
gem 'resque-status', '~> 0.3.3'
gem 'resque_mailer', '~> 2.1.0'
gem 'perform_later', '~> 1.3.0' # should be after resque_mailer
gem 'russian', '~> 0.6.0'
gem 'highline', '~> 1.6.11'
gem 'state_machine'
gem 'jbuilder'
# gem 'rugged', '~> 0.16.0'
gem 'grack', :git => 'git://github.com/rdblue/grack.git', :require => 'git_http'
gem "grit", :git => 'git://github.com/warpc/grit.git' #, :path => '~/Sites/code/grit'
@ -37,11 +37,12 @@ gem 'rdiscount'
gem 'RedCloth'
gem 'wikicloth'
gem 'unicorn', '~> 4.2.1', :platforms => [:mri, :rbx]
gem 'unicorn', '~> 4.3.1', :platforms => [:mri, :rbx]
gem 'trinidad', '~> 1.0.2', :platforms => :jruby
gem 'newrelic_rpm', '~> 3.3.3', :platforms => [:mri, :rbx]
gem 'newrelic_rpm', '~> 3.3.5', :platforms => [:mri, :rbx]
gem 'whenever', '~> 0.7.3', :require => false
gem 'jbuilder', '~> 0.4.0'
gem 'rails3-jquery-autocomplete', '~> 1.0.7'
gem 'will_paginate', '~> 3.0.3'
gem 'meta-tags', '~> 1.2.5', :require => 'meta_tags'
@ -53,16 +54,15 @@ gem 'rails-backbone', '~> 0.7.2'
group :assets do
gem 'sass-rails', '~> 3.2.5'
gem 'coffee-rails', '~> 3.2.2'
gem 'compass-rails', '~> 1.0.1'
gem 'compass-rails', '~> 1.0.2'
gem 'uglifier', '~> 1.2.4'
gem 'therubyracer', '~> 0.10.1', :platforms => [:mri, :rbx]
gem 'therubyrhino', '~> 1.73.1', :platforms => :jruby
end
group :production do
gem "airbrake", '~> 3.0.9'
gem "airbrake", '~> 3.1.1'
gem 'bluepill', '~> 0.0.60', :require => false
gem 'daemons', '1.1.6' # Try to upgrade 1.1.8 to avoid tons DJ bugs?
end
group :development do
@ -78,8 +78,8 @@ group :development do
end
group :test do
gem 'rspec-rails', '~> 2.9.0', :group => 'development'
gem 'factory_girl_rails', '~> 3.1.0'
gem 'rspec-rails', '~> 2.10.1', :group => 'development'
gem 'factory_girl_rails', '~> 3.4.0'
gem 'rr', '~> 1.0.4'
gem 'shoulda'
end

View File

@ -25,40 +25,40 @@ GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.9)
actionmailer (3.2.3)
actionpack (= 3.2.3)
actionmailer (3.2.6)
actionpack (= 3.2.6)
mail (~> 2.4.4)
actionpack (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
actionpack (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.3)
activesupport (= 3.2.3)
sprockets (~> 2.1.3)
activemodel (3.2.6)
activesupport (= 3.2.6)
builder (~> 3.0.0)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activerecord (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activesupport (3.2.3)
activeresource (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
activesupport (3.2.6)
i18n (~> 0.6)
multi_json (~> 1.0)
airbrake (3.0.9)
airbrake (3.1.1)
activesupport
builder
albino (1.3.3)
posix-spawn (>= 0.3.6)
ancestry (1.2.5)
activerecord (>= 2.2.2)
ancestry (1.3.0)
activerecord (>= 2.3.14)
arel (3.0.2)
bcrypt-ruby (3.0.1)
blankslate (2.1.2.4)
@ -87,13 +87,13 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.3.1)
coffee-script-source (1.3.3)
compass (0.12.1)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
compass-rails (1.0.1)
compass (~> 0.12.0)
compass-rails (1.0.2)
compass (>= 0.12.0, < 0.14)
creole (0.4.2)
daemons (1.1.6)
devise (2.0.4)
@ -106,13 +106,13 @@ GEM
ejs (1.0.0)
erubis (2.7.0)
eventmachine (0.12.10)
execjs (1.3.0)
execjs (1.4.0)
multi_json (~> 1.0)
expression_parser (0.9.0)
factory_girl (3.1.1)
factory_girl (3.4.0)
activesupport (>= 3.0.0)
factory_girl_rails (3.1.0)
factory_girl (~> 3.1.0)
factory_girl_rails (3.4.0)
factory_girl (~> 3.4.0)
railties (>= 3.0.0)
fssm (0.2.9)
github-markup (0.7.2)
@ -125,14 +125,14 @@ GEM
redcarpet
sanitize (~> 2.0.0)
sinatra (~> 1.0)
haml (3.1.4)
haml (3.1.6)
haml-rails (0.3.4)
actionpack (~> 3.0)
activesupport (~> 3.0)
haml (~> 3.0)
railties (~> 3.0)
hashie (1.2.0)
highline (1.6.11)
highline (1.6.12)
hike (1.2.1)
hirb (0.6.2)
i18n (0.6.0)
@ -143,9 +143,11 @@ GEM
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.6)
json (1.7.3)
kgio (2.7.4)
libv8 (3.3.10.4)
macaddr (1.6.1)
systemu (~> 2.5.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@ -162,17 +164,17 @@ GEM
meta-tags (1.2.6)
actionpack
mime-types (1.18)
multi_json (1.3.2)
multi_json (1.3.6)
mustache (0.99.4)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.3.0)
net-ssh (2.5.2)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
newrelic_rpm (3.3.4)
nokogiri (1.5.2)
newrelic_rpm (3.3.5)
nokogiri (1.5.4)
omniauth (1.0.3)
hashie (~> 1.2)
rack
@ -180,12 +182,16 @@ GEM
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.0.7)
paperclip (3.0.2)
paperclip (3.0.4)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types
perform_later (1.3.0)
rails (~> 3.0)
redis
resque
pg (0.13.2)
polyglot (0.3.3)
posix-spawn (0.3.6)
@ -201,14 +207,14 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.3)
actionmailer (= 3.2.3)
actionpack (= 3.2.3)
activerecord (= 3.2.3)
activeresource (= 3.2.3)
activesupport (= 3.2.3)
rails (3.2.6)
actionmailer (= 3.2.6)
actionpack (= 3.2.6)
activerecord (= 3.2.6)
activeresource (= 3.2.6)
activesupport (= 3.2.6)
bundler (~> 1.0)
railties (= 3.2.3)
railties (= 3.2.6)
rails-backbone (0.7.2)
coffee-script (~> 2.2.0)
ejs (~> 1.0.0)
@ -217,14 +223,14 @@ GEM
railties (>= 3.0.0)
rails3-jquery-autocomplete (1.0.7)
rails (~> 3.0)
railties (3.2.3)
actionpack (= 3.2.3)
activesupport (= 3.2.3)
railties (3.2.6)
actionpack (= 3.2.6)
activesupport (= 3.2.6)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
raindrops (0.8.0)
thor (>= 0.14.6, < 2.0)
raindrops (0.9.0)
rake (0.9.2.2)
rdiscount (1.6.8)
rdoc (3.12)
@ -233,36 +239,45 @@ GEM
redis (2.2.2)
redis-namespace (1.0.3)
redis (< 3.0.0)
redisk (0.2.2)
redis (>= 0.1.1)
redis-namespace (>= 0.1.0)
resque (1.20.0)
multi_json (~> 1.0)
redis-namespace (~> 1.0.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
resque-status (0.3.3)
redisk (>= 0.2.1)
resque (~> 1.19)
uuid (~> 2.3)
resque_mailer (2.1.0)
actionmailer (~> 3.0)
rr (1.0.4)
rspec (2.9.0)
rspec-core (~> 2.9.0)
rspec-expectations (~> 2.9.0)
rspec-mocks (~> 2.9.0)
rspec-core (2.9.0)
rspec-expectations (2.9.1)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
rspec-rails (2.9.0)
rspec-mocks (2.10.1)
rspec-rails (2.10.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.9.0)
rspec (~> 2.10.0)
ruby-haml-js (0.0.3)
execjs
sprockets (>= 2.0.0)
ruby-openid (2.1.8)
russian (0.6.0)
i18n (>= 0.5.0)
rvm-capistrano (1.1.0)
rvm-capistrano (1.2.2)
capistrano (>= 2.0.0)
sanitize (2.0.3)
nokogiri (>= 1.4.4, < 1.6)
sass (3.1.16)
sass (3.1.19)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
@ -281,19 +296,20 @@ GEM
skinny (0.2.0)
eventmachine (~> 0.12)
thin (~> 1.2)
sprockets (2.1.2)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
state_machine (1.1.2)
systemu (2.5.1)
therubyracer (0.10.1)
libv8 (~> 3.3.10)
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.14.6)
thor (0.15.2)
tilt (1.3.3)
treetop (1.4.10)
polyglot
@ -302,10 +318,12 @@ GEM
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
unicorn (4.2.1)
unicorn (4.3.1)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
uuid (2.3.5)
macaddr (~> 1.0)
vegas (0.1.11)
rack (>= 1.0.0)
warden (1.1.1)
@ -323,8 +341,8 @@ PLATFORMS
DEPENDENCIES
RedCloth
airbrake (~> 3.0.9)
ancestry (~> 1.2.5)
airbrake (~> 3.1.1)
ancestry (~> 1.3.0)
bluepill (~> 0.0.60)
cancan (~> 1.6.7)
cape
@ -332,37 +350,39 @@ DEPENDENCIES
capistrano_colors
charlock_holmes (~> 0.6.8)
coffee-rails (~> 3.2.2)
compass-rails (~> 1.0.1)
compass-rails (~> 1.0.2)
creole
daemons (= 1.1.6)
devise (~> 2.0.4)
diff-display (~> 0.0.1)
factory_girl_rails (~> 3.1.0)
factory_girl_rails (~> 3.4.0)
gollum (= 1.3.1)
grack!
grit!
haml-rails (~> 0.3.4)
highline (~> 1.6.11)
hirb
jbuilder
jbuilder (~> 0.4.0)
jquery-rails (~> 2.0.2)
mailcatcher
meta-tags (~> 1.2.5)
newrelic_rpm (~> 3.3.3)
newrelic_rpm (~> 3.3.5)
omniauth (~> 1.0.3)
omniauth-openid (~> 1.0.1)
paperclip (~> 3.0.2)
paperclip (~> 3.0.4)
perform_later (~> 1.3.0)
pg (~> 0.13.2)
rails (= 3.2.3)
rails (= 3.2.6)
rails-backbone (~> 0.7.2)
rails3-generators
rails3-jquery-autocomplete (~> 1.0.7)
rdiscount
redcarpet (= 1.17.2)
redhillonrails_core!
resque
resque (~> 1.20.0)
resque-status (~> 0.3.3)
resque_mailer (~> 2.1.0)
rr (~> 1.0.4)
rspec-rails (~> 2.9.0)
rspec-rails (~> 2.10.1)
ruby-haml-js (~> 0.0.3)
russian (~> 0.6.0)
rvm-capistrano
@ -374,7 +394,7 @@ DEPENDENCIES
therubyrhino (~> 1.73.1)
trinidad (~> 1.0.2)
uglifier (~> 1.2.4)
unicorn (~> 4.2.1)
unicorn (~> 4.3.1)
whenever (~> 0.7.3)
wikicloth
will_paginate (~> 3.0.3)

View File

@ -98,8 +98,7 @@ class Platforms::PlatformsController < Platforms::BaseController
end
def destroy
@platform.async(:destroy) if @platform
@platform.destroy # later with resque
flash[:notice] = t("flash.platform.destroyed")
redirect_to platforms_path
end

View File

@ -128,7 +128,7 @@ class Projects::BuildListsController < Projects::BaseController
render :nothing => true, :status => 200
@build_list.async(:publish) if @build_list.auto_publish # && @build_list.can_publish?
@build_list.publish if @build_list.auto_publish # && @build_list.can_publish? # later with resque
end
def circle_build
@ -193,7 +193,7 @@ class Projects::BuildListsController < Projects::BaseController
end
end
end
if @build_list.save and @build_list.publish
if @build_list.save and @build_list.now_publish
redirect_to :back, :notice => t('layout.build_lists.publish_success')
else
redirect_to :back, :notice => t('layout.build_lists.publish_fail')

View File

@ -255,10 +255,7 @@ class Projects::WikiController < Projects::BaseController
unless @committer
p = commit_message.merge({:name => current_user.uname, :email => current_user.email})
@committer = Gollum::Committer.new(@wiki, p)
# @committer.after_commit do |committer, sha1|
# here goes callback for notification
# end
ActivityFeedObserver.instance.async(:after_create, @committer)
GitHook.perform_later!(:notification, :process, {:project_id => @project.id, :actor_name => @committer.actor.name, :commit_sha => @committer.commit})
end
@committer
end

View File

@ -3,9 +3,7 @@
class UserMailer < ActionMailer::Base
default :from => APP_CONFIG['do-not-reply-email']
include Modules::Models::ResqueAsyncMethods
@queue = :notifications
include Resque::Mailer # send email async
def new_user_notification(user)
@user = user

View File

@ -2,10 +2,6 @@
class ActivityFeedObserver < ActiveRecord::Observer
observe :issue, :comment, :user, :build_list
include Modules::Models::ResqueAsyncMethods
@queue = :notifications
def after_create(record)
case record.class.to_s
when 'User'
@ -19,7 +15,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
recipients = record.collect_recipient_ids
recipients.each do |recipient_id|
recipient = User.find(recipient_id)
UserMailer.async(:new_issue_notification, record, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue
UserMailer.new_issue_notification(record, recipient).deliver if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue
ActivityFeed.create(
:user => recipient,
:kind => 'new_issue_notification',
@ -29,7 +25,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
end
if record.assignee_id_changed?
UserMailer.async(:new_issue_notification, record, record.assignee) if record.assignee.notifier.issue_assign && record.assignee.notifier.can_notify
UserMailer.new_issue_notification(record, record.assignee).deliver if record.assignee.notifier.issue_assign && record.assignee.notifier.can_notify
ActivityFeed.create(
:user => record.user,
:kind => 'issue_assign_notification',
@ -43,7 +39,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
subscribes = record.commentable.subscribes
subscribes.each do |subscribe|
if record.user_id != subscribe.user_id
UserMailer.async(:new_comment_notification, record, subscribe.user) if record.can_notify_on_new_comment?(subscribe)
UserMailer.new_comment_notification(record, subscribe.user).deliver if record.can_notify_on_new_comment?(subscribe)
ActivityFeed.create(
:user => subscribe.user,
:kind => 'new_comment_notification',
@ -61,7 +57,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
( (subscribe.project.owner?(subscribe.user) && subscribe.user.notifier.new_comment_commit_repo_owner) or
(subscribe.user.commentor?(record.commentable) && subscribe.user.notifier.new_comment_commit_commentor) or
(subscribe.user.committer?(record.commentable) && subscribe.user.notifier.new_comment_commit_owner) )
UserMailer.async(:new_comment_notification, record, subscribe.user)
UserMailer.new_comment_notification(record, subscribe.user).deliver
end
ActivityFeed.create(
:user => subscribe.user,
@ -97,26 +93,23 @@ class ActivityFeedObserver < ActiveRecord::Observer
end
record.project.owner_and_admin_ids.each do |recipient|
ActivityFeed.create(
ActivityFeed.create!(
:user => User.find(recipient),
:kind => kind,
:data => options
)
end
when 'Gollum::Committer'
actor = User.find_by_uname(record.actor.name)
project_name = record.wiki.path.match(/\/(\w+)\.wiki\.git$/)[1]
project = Project.find_by_name(project_name)
commit_sha = record.commit
#wiki_name = record.wiki.name
when 'Hash' # 'Gollum::Committer'
actor = User.find_by_uname! record[:actor_name]
project = Project.find record[:project_id]
project.owner_and_admin_ids.each do |recipient|
ActivityFeed.create(
ActivityFeed.create!(
:user => User.find(recipient),#record.user,
:kind => 'wiki_new_commit_notification',
:data => {:user_id => actor.id, :user_name => actor.name, :user_email => actor.email, :project_id => project.id,
:project_name => project_name, :commit_sha => commit_sha, :project_owner => project.owner.uname}
:project_name => project.name, :commit_sha => record[:commit_sha], :project_owner => project.owner.uname}
)
end
end
@ -126,7 +119,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
case record.class.to_s
when 'Issue'
if record.assignee_id && record.assignee_id_changed?
UserMailer.async(:issue_assign_notification, record, record.assignee) if record.assignee.notifier.issue_assign && record.assignee.notifier.can_notify
UserMailer.issue_assign_notification(record, record.assignee).deliver if record.assignee.notifier.issue_assign && record.assignee.notifier.can_notify
ActivityFeed.create(
:user => record.assignee,
:kind => 'issue_assign_notification',

View File

@ -3,10 +3,12 @@ class GitHook
attr_reader :repo, :newrev, :oldrev, :newrev_type, :oldrev_type, :refname,
:change_type, :rev, :rev_type, :refname_type, :owner, :project
include Resque::Plugins::Status
def initialize(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type)
@repo, @newrev, @oldrev, @refname, @newrev_type, @oldrev_type = repo, newrev, oldrev, ref, newrev_type, oldrev_type
if @owner = User.where(:uname => owner_uname).first || Group.where(:uname => owner_uname).first
@project = @owner.projects.where(:name => repo).first
if @owner = User.where(:uname => owner_uname).first || Group.where(:uname => owner_uname).first!
@project = @owner.own_projects.where(:name => repo).first!
end
@change_type = git_change_type
git_revision_types
@ -55,4 +57,8 @@ class GitHook
@refname_type= "*** Unknown type of update to $refname (#{rev_type})"
end
end
def self.process(*args)
ActivityFeedObserver.instance.after_create(args.size > 1 ? GitHook.new(*args) : args.first)
end
end

View File

@ -12,10 +12,6 @@ class MassBuild < ActiveRecord::Base
after_create :build_all
include Modules::Models::ResqueAsyncMethods
@queue = :clone_and_build
def initialize(args = nil)
super
@ -28,12 +24,12 @@ class MassBuild < ActiveRecord::Base
# ATTENTION: repositories and arches must be set before calling this method!
def build_all
platform.async(:build_all,
platform.build_all(
:mass_build_id => self.id,
:user => self.user,
:repositories => self.repositories,
:arches => self.arches,
:auto_publish => self.auto_publish
)
) # later with resque
end
end

View File

@ -47,9 +47,6 @@ class Platform < ActiveRecord::Base
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
include Modules::Models::Owner
include Modules::Models::ResqueAsyncMethods
@queue = :clone_and_build
def urpmi_list(host, pair = nil)
blank_pair = {:login => 'login', :pass => 'password'}
@ -121,7 +118,7 @@ class Platform < ActiveRecord::Base
def full_clone(attrs = {})
base_clone(attrs).tap do |c|
with_skip {c.save} and c.clone_relations(self) and c.async(:xml_rpc_clone)
with_skip {c.save} and c.clone_relations(self) and c.xml_rpc_clone # later with resque
end
end
@ -175,17 +172,19 @@ class Platform < ActiveRecord::Base
begin
p.build_for(self, user, arch, auto_publish, mass_build_id)
rescue RuntimeError, Exception
p.async(:build_for, self, user, arch, auto_publish, mass_build_id)
# p.async(:build_for, self, user, arch, auto_publish, mass_build_id) # TODO need this?
end
end
end
end
end
end
later :build_all, :loner => true, :queue => :clone_build
def destroy
with_skip {super} # avoid cascade XML RPC requests
end
later :destroy, :loner => true, :queue => :clone_build
protected
@ -219,6 +218,7 @@ class Platform < ActiveRecord::Base
raise "Failed to clone platform #{old_name} with code #{result}. Path: #{build_path(old_name)} to platform #{new_name}"
end
end
later :xml_rpc_clone, :loner => true, :queue => :clone_build
def freeze_platform
if released_changed? && released == true

View File

@ -41,12 +41,12 @@ class Project < ActiveRecord::Base
after_create :attach_to_personal_repository
after_create :create_git_repo
after_create {|p| p.async(:fork_git_repo) unless is_root?}
after_create {|p| p.fork_git_repo unless is_root?} # later with resque
after_save :create_wiki
after_destroy :destroy_git_repo
after_destroy :destroy_wiki
after_save {|p| p.async(:import_attached_srpm) if p.srpm?} # should be after create_git_repo
after_save {|p| p.import_attached_srpm if p.srpm?} # later with resque # should be after create_git_repo
# after_rollback lambda { destroy_git_repo rescue true if new_record? }
has_ancestry
@ -54,9 +54,6 @@ class Project < ActiveRecord::Base
has_attached_file :srpm
include Modules::Models::Owner
include Modules::Models::ResqueAsyncMethods
@queue = :fork_import_hook
def to_param
name
@ -222,11 +219,6 @@ class Project < ActiveRecord::Base
owner == user
end
def self.process_hook(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type)
rec = GitHook.new(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type)
ActivityFeedObserver.instance.after_create rec
end
def owner_and_admin_ids
recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) }
recipients = recipients | [self.owner_id] if self.owner_type == 'User'
@ -255,14 +247,15 @@ class Project < ActiveRecord::Base
def create_git_repo
if is_root?
Grit::Repo.init_bare(path)
async(:write_hook)
write_hook # later with resque
end
end
def fork_git_repo
dummy = Grit::Repo.new(path) rescue parent.git_repository.repo.fork_bare(path)
write_hook
now_write_hook
end
later :fork_git_repo, :loner => true, :queue => :fork_import
def destroy_git_repo
FileUtils.rm_rf path
@ -274,7 +267,7 @@ class Project < ActiveRecord::Base
self.srpm = nil; save # clear srpm
end
end
later :import_attached_srpm, :loner => true, :queue => :fork_import
def create_wiki
if has_wiki && !FileTest.exist?(wiki_path)
@ -294,7 +287,7 @@ class Project < ActiveRecord::Base
hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook")
FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook)
File.open(hook, 'a') do |f|
s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rails runner 'Project.async(:process_hook, \\\"$owner\\\", \\\"$reponame\\\", \\\"$newrev\\\", \\\"$oldrev\\\", \\\"$ref\\\", \\\"$newrev_type\\\", \\\"$oldrev_type\\\")'\""
s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rake hook:enqueue[$owner,$reponame,$newrev,$oldrev,$ref,$newrev_type,$oldrev_type]\""
s << " > /dev/null 2>&1" if is_production
s << "\ndone\n"
f.write(s)
@ -307,4 +300,5 @@ class Project < ActiveRecord::Base
rescue Exception # FIXME
end
later :write_hook, :loner => true, :queue => :hook
end

View File

@ -16,10 +16,6 @@ class Repository < ActiveRecord::Base
attr_accessible :name, :description
attr_readonly :name, :platform_id
include Modules::Models::ResqueAsyncMethods
@queue = :clone_and_build
def base_clone(attrs = {})
dup.tap do |c|
c.platform_id = nil
@ -33,10 +29,11 @@ class Repository < ActiveRecord::Base
from.projects.find_each {|p| self.projects << p}
end
end
later :clone_relations, :loner => true, :queue => :clone_build
def full_clone(attrs = {})
base_clone(attrs).tap do |c|
with_skip {c.save} and c.async(:clone_relations, self)
with_skip {c.save} and c.clone_relations(self) # later with resque
end
end

View File

@ -1,8 +1,8 @@
- if owner.projects.exists? :name => @project.name
- if owner.own_projects.exists? :name => @project.name
- is_group = owner.class == Group ? "(#{t 'activerecord.models.group'})" : ''
%p.center
=t 'layout.projects.already_exists'
=link_to "#{owner.uname}/#{@project.name} #{is_group}", project_path(owner.projects.by_name(@project.name).first)
=link_to "#{owner.uname}/#{@project.name} #{is_group}", project_path(owner, @project.name)
- else
= form_for @project, :url => fork_project_path(@project), :html => { :class => :form, :multipart => true, :method => :post } do |f|
= hidden_field_tag :group, owner.id if owner.class == Group

View File

@ -36,9 +36,7 @@ set :deploy_via, :remote_cache
require './lib/recipes/nginx'
require './lib/recipes/unicorn'
#require './lib/recipes/bluepill'
set :workers_count, 4
require './lib/recipes/resque'
namespace :deploy do

View File

@ -0,0 +1,13 @@
require 'resque/server'
require 'resque/status_server'
::ResqueServer = ::Resque::Server # need for CanCan
Resque::Mailer.default_queue_name = :notification
Resque::Mailer.excluded_environments = [:test]
unless Rails.env.test?
PerformLater.config.enabled = true # this will default to false if unset
end
Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds

View File

@ -12,6 +12,3 @@ Rosa::Application.config.middleware.insert_after ::Rails::Rack::Logger, ::Grack:
Rosa::Application.config.middleware.insert_before ::Grack::Handler, ::Grack::Auth
Rosa::Application.config.action_mailer.default_url_options = { :host => APP_CONFIG['action_mailer_host'] } if APP_CONFIG['action_mailer_host']
require 'resque/server'
::ResqueServer = ::Resque::Server # need for CanCan

View File

@ -8,7 +8,7 @@ Bluepill.application(app_name, :log_file => "/srv/rosa_build/shared/log/bluepill
app.process("resque") do |process|
process.group = "resque"
pid_path = File.join(app.working_dir, 'tmp', 'pids', 'resque.pid')
process.start_command = "bundle exec rake resque:work QUEUE=fork_and_import PIDFILE=#{ pid_path } BACKGROUND=yes"
process.start_command = "bundle exec rake resque:work QUEUE=fork_import,hook,clone_build,notification PIDFILE=#{ pid_path } BACKGROUND=yes"
process.pid_file = pid_path
process.stop_command = "kill -QUIT {{PID}}"
process.daemonize = true

View File

@ -0,0 +1,22 @@
class DropDelayedJobs < ActiveRecord::Migration
def up
drop_table :delayed_jobs
end
def down
create_table :delayed_jobs do |t|
t.integer "priority", :default => 0
t.integer "attempts", :default => 0
t.text "handler"
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by"
t.datetime "created_at"
t.datetime "updated_at"
t.string "queue", :default => "default"
end
add_index :delayed_jobs, ["priority", "run_at"], :name => "delayed_jobs_priority"
end
end

View File

@ -11,14 +11,14 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120529130537) do
ActiveRecord::Schema.define(:version => 20120609163454) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
t.string "kind"
t.text "data"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "advisories", :force => true do |t|
@ -136,22 +136,6 @@ ActiveRecord::Schema.define(:version => 20120529130537) do
t.integer "project_id"
end
create_table "delayed_jobs", :force => true do |t|
t.integer "priority", :default => 0
t.integer "attempts", :default => 0
t.text "handler"
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by"
t.datetime "created_at"
t.datetime "updated_at"
t.string "queue", :default => "default"
end
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "event_logs", :force => true do |t|
t.integer "user_id"
t.string "user_name"
@ -304,25 +288,27 @@ ActiveRecord::Schema.define(:version => 20120529130537) do
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_package", :default => true, :null => false
t.integer "average_build_time", :default => 0, :null => false
t.integer "build_count", :default => 0, :null => false
end
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
create_table "register_requests", :force => true do |t|
t.string "name"
t.string "email"
t.string "token"
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "interest"
t.text "more"
end
@ -376,7 +362,6 @@ ActiveRecord::Schema.define(:version => 20120529130537) do
t.string "name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token"
t.datetime "remember_created_at"
t.datetime "created_at"
@ -384,11 +369,8 @@ ActiveRecord::Schema.define(:version => 20120529130537) do
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.datetime "reset_password_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.text "professional_experience"
t.string "site"
t.string "company"
@ -400,6 +382,9 @@ ActiveRecord::Schema.define(:version => 20120529130537) do
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "authentication_token"
t.integer "build_priority", :default => 50
end

View File

@ -1,32 +0,0 @@
# -*- encoding : utf-8 -*-
module Modules
module Models
module ResqueAsyncMethods
extend ActiveSupport::Concern
included do
# We can pass this any Repository instance method that we want to
# run later.
def async(method, *args)
Resque.enqueue(self.class, id, method, *args)
end
end
module ClassMethods
# This will be called by a worker when a job needs to be processed
def perform(id, method, *args)
unless id.nil?
find(id).send(method, *args)
else
send(method, *args)
end
end
def async(method, *args)
Resque.enqueue(self, nil, method, *args)
end
end
end
end
end

View File

@ -20,11 +20,12 @@ Capistrano::Configuration.instance(:must_exist).load do
end
def stop_workers
run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'`"
#run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'`"
run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1 &"
end
def start_workers
run "cd #{fetch :current_path} && COUNT=#{ workers_count } QUEUE=fork_import_hook,clone_and_build,notifications #{ rails_env } BACKGROUND=yes bundle exec rake resque:workers"
run "cd #{fetch :current_path} && COUNT=#{ workers_count } QUEUE=fork_import,hook,clone_build,notification #{ rails_env } BACKGROUND=yes bundle exec rake resque:workers"
end
end
end

View File

@ -6,7 +6,7 @@ namespace :hook do
hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook")
FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook)
File.open(hook, 'a') do |f|
s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rails runner 'Project.async(:process_hook, \\\"$owner\\\", \\\"$reponame\\\", \\\"$newrev\\\", \\\"$oldrev\\\", \\\"$ref\\\", \\\"$newrev_type\\\", \\\"$oldrev_type\\\")'\""
s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rake hook:enqueue[$owner,$reponame,$newrev,$oldrev,$ref,$newrev_type,$oldrev_type]\""
s << " > /dev/null 2>&1" if is_production
s << "\ndone\n"
f.write(s)
@ -32,6 +32,14 @@ namespace :hook do
FileUtils.rm_rf(hook)
end
desc 'Enqueue hook process'
task :enqueue, :owner, :reponame, :newrev, :oldrev, :ref, :newrev_type, :oldrev_type do |t, args|
# require 'resque'
require './app/models/git_hook'
PerformLater.config.enabled = true unless Rails.env.test?
GitHook.perform_later!(:hook, :process, *args.to_hash.values)
end
desc "remove git hook from all repos"
task :remove => :environment do
say "process.."

View File

@ -1,6 +0,0 @@
#!/usr/bin/env ruby
ENV['RAILS_ENV'] ||= "production"
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize

View File

@ -43,7 +43,7 @@ def test_git_commit(project)
project.git_repository.repo.index.commit('Test commit')
end
#Delayed::Worker.delay_jobs = false # Execute all jobs realtime
Resque.inline = true
# Add testing root_path
%x(rm -Rf #{Rails.root}/tmp/test_root)