diff --git a/Gemfile b/Gemfile index 0b4ded308..2a7ce25f2 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 50cbcd2a7..31ab968c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 50aacb986..347704c40 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -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 diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 59059cef7..a3c27b724 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -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') diff --git a/app/controllers/projects/wiki_controller.rb b/app/controllers/projects/wiki_controller.rb index c56d73dc9..30a78d38c 100644 --- a/app/controllers/projects/wiki_controller.rb +++ b/app/controllers/projects/wiki_controller.rb @@ -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 diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 82b8be5b8..e19cb799f 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -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| diff --git a/app/models/ability.rb b/app/models/ability.rb index c1b61a4a9..743572488 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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 diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index 023c1e9f6..94a12fbc2 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -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', diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 3cee985fb..65202ee0e 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -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 diff --git a/app/models/git_hook.rb b/app/models/git_hook.rb index 2f39d9cbf..ed9639902 100644 --- a/app/models/git_hook.rb +++ b/app/models/git_hook.rb @@ -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 diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 1afe9a99b..1c2f5c3ad 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -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 diff --git a/app/models/platform.rb b/app/models/platform.rb index bde879c34..580def2c8 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -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 diff --git a/app/models/product.rb b/app/models/product.rb index 80d4945e4..013ef34b1 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 2f656be2c..fb0e06e3f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/models/repository.rb b/app/models/repository.rb index 5318b93ba..57c741790 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 diff --git a/app/views/admin/base/_submenu.html.haml b/app/views/admin/base/_submenu.html.haml index bed7e8f02..2255ddfd1 100644 --- a/app/views/admin/base/_submenu.html.haml +++ b/app/views/admin/base/_submenu.html.haml @@ -1,2 +1,2 @@ - content_for :submenu do - %nav= render 'layouts/menu/top', :which_menu => 'admins_menu' \ No newline at end of file + %nav= render 'layouts/menu/top', :which_menu => 'admins_menu' diff --git a/app/views/layouts/menu/_top.html.haml b/app/views/layouts/menu/_top.html.haml index e5ed2e1c0..f74e0d84e 100644 --- a/app/views/layouts/menu/_top.html.haml +++ b/app/views/layouts/menu/_top.html.haml @@ -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') \ No newline at end of file diff --git a/app/views/projects/git/base/_choose_fork.html.haml b/app/views/projects/git/base/_choose_fork.html.haml index 8bffb0d33..4288bf9a8 100644 --- a/app/views/projects/git/base/_choose_fork.html.haml +++ b/app/views/projects/git/base/_choose_fork.html.haml @@ -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 diff --git a/config/deploy.rb b/config/deploy.rb index 0c69a6379..41f67ab13 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -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" diff --git a/config/initializers/admin.rb b/config/initializers/admin.rb deleted file mode 100644 index 8ef8929ef..000000000 --- a/config/initializers/admin.rb +++ /dev/null @@ -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 diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb new file mode 100644 index 000000000..f3e8d36bb --- /dev/null +++ b/config/initializers/resque.rb @@ -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 diff --git a/config/locales/menu.en.yml b/config/locales/menu.en.yml index 73d6e994b..b12e73c29 100644 --- a/config/locales/menu.en.yml +++ b/config/locales/menu.en.yml @@ -38,3 +38,4 @@ en: users: Users register_requests: Invites event_logs: Event log + resque_server: Resque diff --git a/config/locales/menu.ru.yml b/config/locales/menu.ru.yml index 0c7c10a16..6850b6b00 100644 --- a/config/locales/menu.ru.yml +++ b/config/locales/menu.ru.yml @@ -38,3 +38,4 @@ ru: users: Пользователи register_requests: Инвайты event_logs: Лог событий + resque_server: Resque diff --git a/config/production.pill b/config/production.pill index dff582d31..4be8c85d4 100644 --- a/config/production.pill +++ b/config/production.pill @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 02abff2e0..569a0f939 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] diff --git a/db/migrate/20120609163454_drop_delayed_jobs.rb b/db/migrate/20120609163454_drop_delayed_jobs.rb new file mode 100644 index 000000000..c1113565e --- /dev/null +++ b/db/migrate/20120609163454_drop_delayed_jobs.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index beb20f8b3..d2af06b79 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 => 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" diff --git a/lib/ext/rails/owner_constraint.rb b/lib/ext/rails/constraints.rb similarity index 73% rename from lib/ext/rails/owner_constraint.rb rename to lib/ext/rails/constraints.rb index 10f091e3f..2ec8ef342 100644 --- a/lib/ext/rails/owner_constraint.rb +++ b/lib/ext/rails/constraints.rb @@ -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 diff --git a/lib/recipes/bluepill.rb b/lib/recipes/bluepill.rb index f09965eb8..979f83af2 100644 --- a/lib/recipes/bluepill.rb +++ b/lib/recipes/bluepill.rb @@ -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 diff --git a/lib/recipes/delayed_job.rb b/lib/recipes/delayed_job.rb deleted file mode 100644 index 1db2ba6df..000000000 --- a/lib/recipes/delayed_job.rb +++ /dev/null @@ -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 diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index 439200e0a..7f42fd653 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -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 diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index cd3841fba..1b7e3d964 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -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.." diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 1649e395a..b031980bf 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -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 diff --git a/script/delayed_job b/script/delayed_job deleted file mode 100755 index da53fc1ff..000000000 --- a/script/delayed_job +++ /dev/null @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7eab2ddcd..843efa51f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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)