[issue #428] Merge branch 'master' into 428-advisory

Conflicts:
	db/schema.rb
This commit is contained in:
George Vinogradov 2012-06-19 02:57:39 +04:00
commit 735afaea15
35 changed files with 303 additions and 299 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,15 +12,15 @@ 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 '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'
@ -36,11 +36,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'
@ -52,16 +53,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
@ -77,8 +77,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,20 +87,15 @@ 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)
delayed_job (3.0.2)
activesupport (~> 3.0)
delayed_job_active_record (0.3.2)
activerecord (> 2.1.0)
delayed_job (~> 3.0.0)
devise (2.0.4)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
@ -111,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)
@ -130,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)
@ -148,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)
@ -167,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
@ -185,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)
@ -206,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)
@ -222,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)
@ -238,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)
@ -286,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
@ -307,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)
@ -328,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
@ -337,38 +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)
delayed_job_active_record (~> 0.3.2)
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
@ -379,7 +393,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.delay.destroy if @platform
@platform.destroy # later with resque
flash[:notice] = t("flash.platform.destroyed")
redirect_to platforms_path
end

View File

@ -132,7 +132,7 @@ class Projects::BuildListsController < Projects::BaseController
render :nothing => true, :status => 200
@build_list.delay.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
@ -197,7 +197,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.after_create(@committer).delay
GitHook.perform_later!(:notification, :process, {:project_id => @project.id, :actor_name => @committer.actor.name, :commit_sha => @committer.commit})
end
@committer
end

View File

@ -3,6 +3,8 @@
class UserMailer < ActionMailer::Base
default :from => APP_CONFIG['do-not-reply-email']
include Resque::Mailer # send email async
def new_user_notification(user)
@user = user
mail(:to => user.email, :subject => I18n.t("notifications.subjects.new_user_notification", :project_name => APP_CONFIG['project_name'])) do |format|

View File

@ -29,8 +29,6 @@ class Ability
else # Registered user rights
if user.admin?
can :manage, :all
# Resque authorize
can :manage, Resque
# Protection
cannot :approve, RegisterRequest, :approved => true
cannot :reject, RegisterRequest, :rejected => true

View File

@ -15,7 +15,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
recipients = record.collect_recipient_ids
recipients.each do |recipient_id|
recipient = User.find(recipient_id)
UserMailer.delay.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',
@ -25,7 +25,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
end
if record.assignee_id_changed?
UserMailer.delay.issue_assign_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',
@ -39,7 +39,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
subscribes = record.commentable.subscribes
subscribes.each do |subscribe|
if record.user_id != subscribe.user_id
UserMailer.delay.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',
@ -57,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.delay.new_comment_notification(record, subscribe.user)
UserMailer.new_comment_notification(record, subscribe.user).deliver
end
ActivityFeed.create(
:user => subscribe.user,
@ -93,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
@ -122,7 +119,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
case record.class.to_s
when 'Issue'
if record.assignee_id && record.assignee_id_changed?
UserMailer.delay.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

@ -132,6 +132,7 @@ class BuildList < ActiveRecord::Base
update_attribute(:status, has_published == 0 ? BUILD_PUBLISH : FAILED_PUBLISH)
return has_published == 0
end
later :publish, :loner => true, :queue => :clone_build
def can_publish?
status == BuildServer::SUCCESS or status == FAILED_PUBLISH

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

@ -24,12 +24,12 @@ class MassBuild < ActiveRecord::Base
# ATTENTION: repositories and arches must be set before calling this method!
def build_all
platform.delay.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

@ -21,7 +21,7 @@ class Platform < ActiveRecord::Base
validates :description, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\.]+$/ }
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
before_create :create_directory, :if => lambda {Thread.current[:skip]} # TODO remove this when core will be ready
@ -104,11 +104,10 @@ class Platform < ActiveRecord::Base
end
def base_clone(attrs = {}) # :description, :name, :owner
clone.tap do |c|
# c.attributes = attrs #
attrs.each {|k,v| c.send("#{k}=", v)}
c.updated_at = nil; c.created_at = nil # :id = nil
c.parent = self
dup.tap do |c|
attrs.each {|k,v| c.send("#{k}=", v)} # c.attributes = attrs
c.updated_at = nil; c.created_at = nil
c.parent = self; c.released = false
end
end
@ -119,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.delay.xml_rpc_clone
with_skip {c.save} and c.clone_relations(self) and c.xml_rpc_clone # later with resque
end
end
@ -173,17 +172,19 @@ class Platform < ActiveRecord::Base
begin
p.build_for(self, user, arch, auto_publish, mass_build_id)
rescue RuntimeError, Exception
p.delay.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
@ -217,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

@ -54,10 +54,10 @@ class Product < ActiveRecord::Base
end
def full_clone(attrs = {})
clone.tap do |c| # dup
dup.tap do |c|
c.platform_id = nil
attrs.each {|k,v| c.send("#{k}=", v)}
c.updated_at = nil; c.created_at = nil # :id = nil
c.updated_at = nil; c.created_at = nil
end
end

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
@ -55,20 +55,6 @@ class Project < ActiveRecord::Base
include Modules::Models::Owner
@queue = :fork_and_import
# This will be called by a worker when a job needs to be processed
def self.perform(id, method, *args)
find(id).send(method, *args)
end
# We can pass this any Repository instance method that we want to
# run later.
def async(method, *args)
Resque.enqueue(Project, id, method, *args)
end
def to_param
name
end
@ -233,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'
@ -266,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
@ -285,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)
@ -305,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.delay(:queue => \\\"hook\\\").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)
@ -318,4 +300,5 @@ class Project < ActiveRecord::Base
rescue Exception # FIXME
end
later :write_hook, :loner => true, :queue => :hook
end

View File

@ -17,10 +17,10 @@ class Repository < ActiveRecord::Base
attr_readonly :name, :platform_id
def base_clone(attrs = {})
clone.tap do |c| # dup
dup.tap do |c|
c.platform_id = nil
attrs.each {|k,v| c.send("#{k}=", v)}
c.updated_at = nil; c.created_at = nil # :id = nil
c.updated_at = nil; c.created_at = nil
end
end
@ -29,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.delay.clone_relations(self)
with_skip {c.save} and c.clone_relations(self) # later with resque
end
end

View File

@ -1,2 +1,2 @@
- content_for :submenu do
%nav= render 'layouts/menu/top', :which_menu => 'admins_menu'
%nav= render 'layouts/menu/top', :which_menu => 'admins_menu'

View File

@ -4,4 +4,4 @@
- if can? :index, base.to_s.classify.constantize
%li= link_to title, send(:"#{namespace}#{base}_path"), :class => top_menu_class(base)
- if current_user.try(:admin?) and which_menu == 'top_menu'
%li= link_to t('admins_menu_header'), admin_users_path, :class => top_menu_class('admin')
%li= link_to t('admins_menu_header'), admin_users_path, :class => top_menu_class('admin')

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

@ -35,8 +35,8 @@ set :deploy_via, :remote_cache
require './lib/recipes/nginx'
require './lib/recipes/unicorn'
require './lib/recipes/bluepill'
require './lib/recipes/delayed_job'
#require './lib/recipes/bluepill'
set :workers_count, 4
require './lib/recipes/resque'
namespace :deploy do
@ -83,12 +83,11 @@ end
after "deploy:finalize_update", "deploy:symlink_all"
after "deploy:update_code", "deploy:migrate"
after "deploy:setup", "deploy:symlink_pids"
# after "deploy:restart", "bluepill:start" # "bluepill:processes:restart_dj" # "bluepill:restart"
# DJ
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart"
# Bluepill
#after "deploy:restart", "bluepill:restart" # "bluepill:processes:restart_dj" # "bluepill:restart"
#after "deploy:start", "bluepill:start"
#after "deploy:stop", "bluepill:stop"
# Resque
after "deploy:stop", "resque:stop"

View File

@ -1,8 +0,0 @@
# config/initializers/admin.rb
class CanAccessResque
def self.matches?(request)
current_user = request.env['warden'].user
return false if current_user.blank?
Ability.new(current_user).can? :manage, Resque
end
end

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

@ -38,3 +38,4 @@ en:
users: Users
register_requests: Invites
event_logs: Event log
resque_server: Resque

View File

@ -38,3 +38,4 @@ ru:
users: Пользователи
register_requests: Инвайты
event_logs: Лог событий
resque_server: Resque

View File

@ -1,46 +1,53 @@
#! /usr/bin/env ruby
app_name = ENV['APP_NAME'] || 'rosa_build'
Bluepill.application(app_name) do |app|
Bluepill.application(app_name, :log_file => "/srv/rosa_build/shared/log/bluepill.log") do |app|
app.uid = app.gid = 'rosa'
app.working_dir = "/srv/#{app_name}/current"
%w(hook default).each do |queue|
app.process("delayed_job_#{queue}_queue") do |process|
process.start_grace_time = 10.seconds
process.stop_grace_time = 10.seconds
process.restart_grace_time = 10.seconds
process.start_command = "/usr/bin/env ruby script/delayed_job --queue=#{queue} -p #{queue} --pid-dir=/srv/#{app_name}/current/tmp/#{queue}_pids start"
process.stop_command = "/usr/bin/env ruby script/delayed_job --pid-dir=/srv/#{app_name}/current/tmp/#{queue}_pids stop"
process.pid_file = File.join(app.working_dir, 'tmp', "#{queue}_pids", 'delayed_job.pid')
end
end
app.process("newrelic") do |process|
process.start_grace_time = 10.seconds
process.stop_grace_time = 10.seconds
process.restart_grace_time = 10.seconds
path = File.join(app.working_dir, 'tmp', 'pids', 'newrelic.pid')
process.start_command = "/usr/bin/env /usr/local/bin/nrsysmond -c /etc/newrelic/nrsysmond.cfg -p #{path}"
process.pid_file = path
end
app.process("unicorn") do |process|
process.start_grace_time = 8.seconds
process.stop_grace_time = 5.seconds
process.restart_grace_time = 13.seconds
process.start_command = "bundle exec unicorn -l /tmp/#{app_name}_unicorn.sock -E production -c config/unicorn.rb -D"
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_import,hook,clone_build,notification PIDFILE=#{ pid_path } BACKGROUND=yes"
process.pid_file = pid_path
process.stop_command = "kill -QUIT {{PID}}"
process.restart_command = "kill -USR2 {{PID}}"
process.pid_file = File.join(app.working_dir, 'tmp', 'pids', 'unicorn.pid')
process.daemonize = true
process.start_grace_time = 5.seconds
process.stop_grace_time = 5.seconds
process.restart_grace_time = 5.seconds
process.monitor_children do |child_process|
child_process.stop_command = "kill -QUIT {{PID}}"
child_process.checks :mem_usage, :every => 10.seconds, :below => 150.megabytes, :times => [3,4], :fires => :stop
child_process.checks :cpu_usage, :every => 10.seconds, :below => 20, :times => [3,4], :fires => :stop
end
#process.monitor_children do |c|
# c.stop_command = "kill -USR1 {{PID}}" # TODO: Are we really need this?
# c.checks :mem_usage, :every => 30.seconds, :below => 80.megabytes, :fires => :stop
# c.checks :running_time, :every => 30.seconds, :below => 10.minutes, :fires => :stop
#end
end
#app.process("newrelic") do |process|
# process.start_grace_time = 10.seconds
# process.stop_grace_time = 10.seconds
# process.restart_grace_time = 10.seconds
# path = File.join(app.working_dir, 'tmp', 'pids', 'newrelic.pid')
# process.start_command = "/usr/bin/env /usr/local/bin/nrsysmond -c /etc/newrelic/nrsysmond.cfg -p #{path}"
# process.pid_file = path
#end
#app.process("unicorn") do |process|
# process.start_grace_time = 8.seconds
# process.stop_grace_time = 5.seconds
# process.restart_grace_time = 13.seconds
# process.start_command = "bundle exec unicorn -l /tmp/#{app_name}_unicorn.sock -E production -c config/unicorn.rb -D"
# process.stop_command = "kill -QUIT {{PID}}"
# process.restart_command = "kill -USR2 {{PID}}"
# process.pid_file = File.join(app.working_dir, 'tmp', 'pids', 'unicorn.pid')
# process.monitor_children do |child_process|
# child_process.stop_command = "kill -QUIT {{PID}}"
# child_process.checks :mem_usage, :every => 10.seconds, :below => 150.megabytes, :times => [3,4], :fires => :stop
# child_process.checks :cpu_usage, :every => 10.seconds, :below => 20, :times => [3,4], :fires => :stop
# end
#end
end

View File

@ -1,7 +1,5 @@
# -*- encoding : utf-8 -*-
Rosa::Application.routes.draw do
require 'resque/server'
devise_scope :users do
get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end
@ -24,10 +22,6 @@ Rosa::Application.routes.draw do
end
namespace :admin do
constraints CanAccessResque do
mount Resque::Server, at: 'resque'
end
resources :users do
get :list, :on => :collection
end
@ -39,6 +33,9 @@ Rosa::Application.routes.draw do
end
end
resources :event_logs, :only => :index
constraints AdminAccess do
mount Resque::Server => 'resque'
end
end
resources :advisories, :only => [:index, :show]

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,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120607153342) do
ActiveRecord::Schema.define(:version => 20120609163454) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -167,22 +167,6 @@ ActiveRecord::Schema.define(:version => 20120607153342) 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"
@ -413,7 +397,6 @@ ActiveRecord::Schema.define(:version => 20120607153342) do
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
t.text "ssh_key"
t.string "uname"
t.string "role"
t.string "language", :default => "en"

View File

@ -10,3 +10,9 @@ class OwnerConstraint
@class_name.send(@finder, request.params[:uname]).present?
end
end
class AdminAccess
def self.matches?(request)
!!request.env['warden'].user.try(:admin?)
end
end

View File

@ -23,13 +23,6 @@ Capistrano::Configuration.instance(:must_exist).load do
task :status, :roles => [:app] do
run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} status"
end
desc "Restart DJ processes"
task :restart_dj, :roles => [:app] do
%w(fork import hook default).each do |queue|
run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart delayed_job_#{queue}_queue"
end
end
end
desc "Start a bluepill process and load a config"
@ -47,5 +40,10 @@ Capistrano::Configuration.instance(:must_exist).load do
task :restart, :roles => [:app] do
processes.stop; stop; start
end
desc "Stop bluepill and monitored services"
task :stop, :roles => [:app] do
processes.stop
end
end
end

View File

@ -1,37 +0,0 @@
# -*- encoding : utf-8 -*-
Capistrano::Configuration.instance(:must_exist).load do
namespace :delayed_job do
def dj_queues
%w(hook default)
end
def rails_env
fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
end
def roles
fetch(:delayed_job_server_role, :app)
end
desc "Stop the delayed_job process"
task :stop, :roles => lambda { roles } do
dj_queues.each do |queue|
run "cd #{current_path};#{rails_env} script/delayed_job --pid-dir=#{shared_path}/pids/#{queue} stop"
end
end
desc "Start the delayed_job process"
task :start, :roles => lambda { roles } do
dj_queues.each do |queue|
run "cd #{current_path};#{rails_env} script/delayed_job --queue=#{queue} -p #{queue} --pid-dir=#{shared_path}/pids/#{queue} start"
end
end
desc "Restart the delayed_job process"
task :restart, :roles => lambda { roles } do
dj_queues.each do |queue|
run "cd #{current_path};#{rails_env} script/delayed_job --queue=#{queue} -p #{queue} --pid-dir=#{shared_path}/pids/#{queue} restart"
end
end
end
end

View File

@ -1,5 +1,6 @@
# -*- encoding : utf-8 -*-
Capistrano::Configuration.instance(:must_exist).load do
namespace :resque do
task :start do
start_workers
@ -19,19 +20,12 @@ Capistrano::Configuration.instance(:must_exist).load do
end
def stop_workers
pids = Array.new
Resque.workers.each do |worker|
pids << worker.to_s.split(/:/).second
end
if pids.size > 0
system("kill -QUIT #{pids.join(' ')}")
end
#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 :release_path} && QUEUE=* bundle exec rake resque:work"
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

@ -5,8 +5,8 @@ namespace :hook do
say "Generate temporary file..."
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.delay(:queue => \\\"hook\\\").process_hook(\\\"$owner\\\", \\\"$reponame\\\", \\\"$newrev\\\", \\\"$oldrev\\\", \\\"$ref\\\", \\\"$newrev_type\\\", \\\"$oldrev_type\\\")'\""
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 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

@ -27,6 +27,32 @@ namespace :import do
say 'DONE'
end
# bundle exec rake import:srpm RAILS_ENV=production BASE=/share/platforms/naulinux5x_personal/tmp/SRPMS LIST=https://dl.dropbox.com/u/984976/nauschool5x.srpms.txt OWNER=naulinux PLATFORM=naulinux REPO=main > log/srpm_naulinux.log
desc 'Import SRPMs as projects'
task :srpm => :environment do
base = ENV['BASE'] || '/share/alt_repos/rsync'
list = ENV['LIST'] #|| 'https://dl.dropbox.com/u/984976/alt_import.txt'
mask = ENV['MASK'] || '*.src.rpm'
owner = User.find_by_uname(ENV['OWNER']) || Group.find_by_uname!(ENV['OWNER'] || 'altlinux')
platform = Platform.find_by_name!(ENV['PLATFORM'] || 'altlinux5')
repo = platform.repositories.find_by_name!(ENV['REPO'] || 'main')
say "START import projects from '#{base}' using '#{list || mask}' for '#{owner.uname}' to repo '#{platform.name}/#{repo.name}'."
repo.project_to_repositories.clear if agree "Clear destination repo #{platform.name}/#{repo.name}?"
(list ? open(list).readlines.map{|n| File.join base, n.chomp.strip} : Dir[File.join base, mask]).each do |path|
print "Processing '#{path}'..."
if name = `rpm -q --qf '[%{Name}]' -p #{path}` and $?.success? and name.present?
p = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id)
p.import_srpm(path, platform.name)
repo.projects << p
print "Ok! - #{p.name}"
else
print 'Fail!'
end
puts
end
say 'DONE'
end
namespace :sync do
desc "Sync all repos"
task :all do

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)