From 8542c608389d7955bc5d6ac241de3c614a23ec9f Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 15 Jun 2012 00:12:29 +0600 Subject: [PATCH 1/7] [refs #522] to fork check own projects --- app/views/projects/git/base/_choose_fork.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From b47b4ec075d50d8ff23e18636a3350befe30a9c1 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Sat, 16 Jun 2012 21:27:46 +0300 Subject: [PATCH 2/7] Update rails and gems. Redo resque jobs enqueue and perform through plugins. Redo emails async sending. Redo hook process. Refactor and code cleanup. Refs #510 --- Gemfile | 28 +-- Gemfile.lock | 162 ++++++++++-------- .../platforms/platforms_controller.rb | 3 +- .../projects/build_lists_controller.rb | 4 +- app/controllers/projects/wiki_controller.rb | 5 +- app/mailers/user_mailer.rb | 4 +- app/models/activity_feed_observer.rb | 29 ++-- app/models/build_list.rb | 1 + app/models/git_hook.rb | 10 +- app/models/mass_build.rb | 6 +- app/models/platform.rb | 10 +- app/models/project.rb | 22 +-- app/models/repository.rb | 7 +- config/deploy.rb | 2 - config/initializers/resque.rb | 13 ++ config/initializers/setup.rb | 3 - config/production.pill | 2 +- .../20120609163454_drop_delayed_jobs.rb | 22 +++ db/schema.rb | 39 ++--- lib/modules/models/resque_async_methods.rb | 32 ---- lib/tasks/hook.rake | 12 +- script/delayed_job | 6 - spec/spec_helper.rb | 2 +- 23 files changed, 205 insertions(+), 219 deletions(-) create mode 100644 config/initializers/resque.rb create mode 100644 db/migrate/20120609163454_drop_delayed_jobs.rb delete mode 100644 lib/modules/models/resque_async_methods.rb delete mode 100755 script/delayed_job diff --git a/Gemfile b/Gemfile index c2ed09aa6..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 ebb8a9ebf..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,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 @@ -373,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 6afc43b9a..4efa1b8b1 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.async(:destroy) if @platform - + @platform.destroy 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 e488ca9f8..af77c762d 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.async(:publish) if @build_list.auto_publish # && @build_list.can_publish? + @build_list.publish if @build_list.auto_publish # && @build_list.can_publish? 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 65e3cac9b..15e778214 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.async(:after_create, @committer) + GitHook.perform_later!(:notifcations, :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 9f1c3535e..67d5e869c 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -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 def new_user_notification(user) @user = user diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index defb8e6b9..94a12fbc2 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -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', diff --git a/app/models/build_list.rb b/app/models/build_list.rb index b5594e04d..44b1f7c4a 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -136,6 +136,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_and_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 ee7570012..559d0012c 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -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,7 +24,7 @@ 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, diff --git a/app/models/platform.rb b/app/models/platform.rb index c905f0bf5..9872a52e1 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -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 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_and_build def destroy with_skip {super} # avoid cascade XML RPC requests end + later :destroy, :loner => true, :queue => :clone_and_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_and_build def freeze_platform if released_changed? && released == true diff --git a/app/models/project.rb b/app/models/project.rb index 0d7d91e48..e22022ee1 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?} 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?} # 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 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_hook 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_hook 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 => :fork_import_hook end diff --git a/app/models/repository.rb b/app/models/repository.rb index 503ce4978..16ef75a87 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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_and_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) end end diff --git a/config/deploy.rb b/config/deploy.rb index 1af5b469b..41f67ab13 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -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 diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb new file mode 100644 index 000000000..a7f53158a --- /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 = 'notifications' +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/initializers/setup.rb b/config/initializers/setup.rb index dd5406b31..5aa0c8a1c 100644 --- a/config/initializers/setup.rb +++ b/config/initializers/setup.rb @@ -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 diff --git a/config/production.pill b/config/production.pill index 4047c5aa6..53f3b273d 100644 --- a/config/production.pill +++ b/config/production.pill @@ -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 PIDFILE=#{ pid_path } BACKGROUND=yes" process.pid_file = pid_path process.stop_command = "kill -QUIT {{PID}}" process.daemonize = true 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 d02f68ff8..b644b0e4c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/lib/modules/models/resque_async_methods.rb b/lib/modules/models/resque_async_methods.rb deleted file mode 100644 index fe3fef009..000000000 --- a/lib/modules/models/resque_async_methods.rb +++ /dev/null @@ -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 - diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index 31dfc5c88..d19e7c0be 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.async(: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!(:fork_import_hook, :process, *args.to_hash.values) + end + desc "remove git hook from all repos" task :remove => :environment do say "process.." 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) From f19e82b3fcd45062aad682787b4731d9d91009ec Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Sun, 17 Jun 2012 01:51:02 +0300 Subject: [PATCH 3/7] Add comments for async method calls. Refs #510 --- app/controllers/platforms/platforms_controller.rb | 2 +- app/controllers/projects/build_lists_controller.rb | 2 +- app/mailers/user_mailer.rb | 2 +- app/models/mass_build.rb | 2 +- app/models/platform.rb | 2 +- app/models/project.rb | 6 +++--- app/models/repository.rb | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 4efa1b8b1..347704c40 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -98,7 +98,7 @@ class Platforms::PlatformsController < Platforms::BaseController end def destroy - @platform.destroy + @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 af77c762d..47fec8ce3 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.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 diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 67d5e869c..e19cb799f 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -3,7 +3,7 @@ class UserMailer < ActionMailer::Base default :from => APP_CONFIG['do-not-reply-email'] - include Resque::Mailer + include Resque::Mailer # send email async def new_user_notification(user) @user = user diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 559d0012c..1c2f5c3ad 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -30,6 +30,6 @@ class MassBuild < ActiveRecord::Base :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 9872a52e1..bdc0c68e4 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -118,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.xml_rpc_clone + with_skip {c.save} and c.clone_relations(self) and c.xml_rpc_clone # later with resque end end diff --git a/app/models/project.rb b/app/models/project.rb index e22022ee1..5ea3caea8 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.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.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 @@ -247,7 +247,7 @@ class Project < ActiveRecord::Base def create_git_repo if is_root? Grit::Repo.init_bare(path) - write_hook + write_hook # later with resque end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 16ef75a87..e36d4cab1 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -33,7 +33,7 @@ class Repository < ActiveRecord::Base def full_clone(attrs = {}) base_clone(attrs).tap do |c| - with_skip {c.save} and c.clone_relations(self) + with_skip {c.save} and c.clone_relations(self) # later with resque end end From 73ec2ec5e958ee43de79fa858b120612c28f5229 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Mon, 18 Jun 2012 14:38:25 +0300 Subject: [PATCH 4/7] Fix typo. Refs #510 --- app/controllers/projects/wiki_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects/wiki_controller.rb b/app/controllers/projects/wiki_controller.rb index 15e778214..2c80f2895 100644 --- a/app/controllers/projects/wiki_controller.rb +++ b/app/controllers/projects/wiki_controller.rb @@ -255,7 +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) - GitHook.perform_later!(:notifcations, :process, {:project_id => @project.id, :actor_name => @committer.actor.name, :commit_sha => @committer.commit}) + GitHook.perform_later!(:notifications, :process, {:project_id => @project.id, :actor_name => @committer.actor.name, :commit_sha => @committer.commit}) end @committer end From bcf4222282304b6c22e652d47c6523266637b524 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Mon, 18 Jun 2012 15:00:57 +0300 Subject: [PATCH 5/7] Remove old style queue. Refs #510 --- app/models/build_list.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 44b1f7c4a..efaa2337d 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -100,10 +100,6 @@ class BuildList < ActiveRecord::Base after_create :place_build after_destroy :delete_container - include Modules::Models::ResqueAsyncMethods - - @queue = :clone_and_build - def self.human_status(status) I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") end From cb8345a2073f9692b2958775d0d06a7d70550bad Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Mon, 18 Jun 2012 17:16:53 +0300 Subject: [PATCH 6/7] Rename and separate queues. Refs #510 --- app/controllers/projects/wiki_controller.rb | 2 +- app/models/build_list.rb | 2 +- app/models/platform.rb | 6 +++--- app/models/project.rb | 6 +++--- app/models/repository.rb | 2 +- config/initializers/resque.rb | 2 +- config/production.pill | 2 +- lib/recipes/resque.rb | 2 +- lib/tasks/hook.rake | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/projects/wiki_controller.rb b/app/controllers/projects/wiki_controller.rb index 2c80f2895..30a78d38c 100644 --- a/app/controllers/projects/wiki_controller.rb +++ b/app/controllers/projects/wiki_controller.rb @@ -255,7 +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) - GitHook.perform_later!(:notifications, :process, {:project_id => @project.id, :actor_name => @committer.actor.name, :commit_sha => @committer.commit}) + 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/models/build_list.rb b/app/models/build_list.rb index efaa2337d..65202ee0e 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -132,7 +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_and_build + later :publish, :loner => true, :queue => :clone_build def can_publish? status == BuildServer::SUCCESS or status == FAILED_PUBLISH diff --git a/app/models/platform.rb b/app/models/platform.rb index bdc0c68e4..580def2c8 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -179,12 +179,12 @@ class Platform < ActiveRecord::Base end end end - later :build_all, :loner => true, :queue => :clone_and_build + 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_and_build + later :destroy, :loner => true, :queue => :clone_build protected @@ -218,7 +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_and_build + later :xml_rpc_clone, :loner => true, :queue => :clone_build def freeze_platform if released_changed? && released == true diff --git a/app/models/project.rb b/app/models/project.rb index 5ea3caea8..e6c40ddb5 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -255,7 +255,7 @@ class Project < ActiveRecord::Base dummy = Grit::Repo.new(path) rescue parent.git_repository.repo.fork_bare(path) now_write_hook end - later :fork_git_repo, :loner => true, :queue => :fork_import_hook + later :fork_git_repo, :loner => true, :queue => :fork_import def destroy_git_repo FileUtils.rm_rf path @@ -267,7 +267,7 @@ class Project < ActiveRecord::Base self.srpm = nil; save # clear srpm end end - later :import_attached_srpm, :loner => true, :queue => :fork_import_hook + later :import_attached_srpm, :loner => true, :queue => :fork_import def create_wiki if has_wiki && !FileTest.exist?(wiki_path) @@ -300,5 +300,5 @@ class Project < ActiveRecord::Base rescue Exception # FIXME end - later :write_hook, :loner => true, :queue => :fork_import_hook + later :write_hook, :loner => true, :queue => :hook end diff --git a/app/models/repository.rb b/app/models/repository.rb index e36d4cab1..57c741790 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -29,7 +29,7 @@ class Repository < ActiveRecord::Base from.projects.find_each {|p| self.projects << p} end end - later :clone_relations, :loner => true, :queue => :clone_and_build + later :clone_relations, :loner => true, :queue => :clone_build def full_clone(attrs = {}) base_clone(attrs).tap do |c| diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index a7f53158a..f3e8d36bb 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -3,7 +3,7 @@ require 'resque/status_server' ::ResqueServer = ::Resque::Server # need for CanCan -Resque::Mailer.default_queue_name = 'notifications' +Resque::Mailer.default_queue_name = :notification Resque::Mailer.excluded_environments = [:test] unless Rails.env.test? diff --git a/config/production.pill b/config/production.pill index 53f3b273d..4be8c85d4 100644 --- a/config/production.pill +++ b/config/production.pill @@ -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_import_hook 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 diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index ae98eb72d..ab0e6c0a2 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -24,7 +24,7 @@ Capistrano::Configuration.instance(:must_exist).load do 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 diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index d19e7c0be..1b7e3d964 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -37,7 +37,7 @@ namespace :hook do # require 'resque' require './app/models/git_hook' PerformLater.config.enabled = true unless Rails.env.test? - GitHook.perform_later!(:fork_import_hook, :process, *args.to_hash.values) + GitHook.perform_later!(:hook, :process, *args.to_hash.values) end desc "remove git hook from all repos" From b90c6acaf7cd062b619c8c2cd1686c300c3a4b8e Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 18 Jun 2012 18:38:54 +0400 Subject: [PATCH 7/7] [refs #510] Add resque workers silent kill to capistrano --- lib/recipes/resque.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index ab0e6c0a2..7f42fd653 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -20,7 +20,8 @@ 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