[refs #510] Add resque async workers
This commit is contained in:
parent
a51737d58c
commit
38b55d769f
|
@ -14,3 +14,4 @@ public/downloads/*
|
|||
*.swp
|
||||
*.tmproj
|
||||
.sass-cache/
|
||||
dump.rdb
|
||||
|
|
1
Gemfile
1
Gemfile
|
@ -15,6 +15,7 @@ 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 'russian', '~> 0.6.0'
|
||||
gem 'highline', '~> 1.6.11'
|
||||
|
||||
|
|
11
Gemfile.lock
11
Gemfile.lock
|
@ -235,6 +235,14 @@ GEM
|
|||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
redcarpet (1.17.2)
|
||||
redis (2.2.2)
|
||||
redis-namespace (1.0.3)
|
||||
redis (< 3.0.0)
|
||||
resque (1.20.0)
|
||||
multi_json (~> 1.0)
|
||||
redis-namespace (~> 1.0.2)
|
||||
sinatra (>= 0.9.2)
|
||||
vegas (~> 0.1.2)
|
||||
rr (1.0.4)
|
||||
rspec (2.9.0)
|
||||
rspec-core (~> 2.9.0)
|
||||
|
@ -303,6 +311,8 @@ GEM
|
|||
kgio (~> 2.6)
|
||||
rack
|
||||
raindrops (~> 0.7)
|
||||
vegas (0.1.11)
|
||||
rack (>= 1.0.0)
|
||||
warden (1.1.1)
|
||||
rack (>= 1.0)
|
||||
whenever (0.7.3)
|
||||
|
@ -356,6 +366,7 @@ DEPENDENCIES
|
|||
rdiscount
|
||||
redcarpet (= 1.17.2)
|
||||
redhillonrails_core!
|
||||
resque
|
||||
rr (~> 1.0.4)
|
||||
rspec-rails (~> 2.9.0)
|
||||
ruby-haml-js (~> 0.0.3)
|
||||
|
|
6
Rakefile
6
Rakefile
|
@ -3,5 +3,11 @@
|
|||
|
||||
require File.expand_path('../config/application', __FILE__)
|
||||
require 'rake'
|
||||
require 'resque/tasks'
|
||||
|
||||
# This fixes connection fail with Postgres server on new fork:
|
||||
task "resque:setup" => :environment do
|
||||
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
|
||||
end
|
||||
|
||||
Rosa::Application.load_tasks
|
||||
|
|
|
@ -41,12 +41,12 @@ class Project < ActiveRecord::Base
|
|||
|
||||
after_create :attach_to_personal_repository
|
||||
after_create :create_git_repo
|
||||
after_create {|p| p.delay(:queue => 'fork', :priority => 20).fork_git_repo unless is_root?}
|
||||
after_create {|p| p.async(:fork_git_repo) unless is_root?}
|
||||
after_save :create_wiki
|
||||
|
||||
after_destroy :destroy_git_repo
|
||||
after_destroy :destroy_wiki
|
||||
after_save {|p| p.delay(:queue => 'import', :priority => 10).import_attached_srpm if p.srpm?} # should be after create_git_repo
|
||||
after_save {|p| p.async(: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
|
||||
|
@ -55,6 +55,20 @@ 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
|
||||
|
@ -252,7 +266,7 @@ class Project < ActiveRecord::Base
|
|||
def create_git_repo
|
||||
if is_root?
|
||||
Grit::Repo.init_bare(path)
|
||||
write_hook.delay(:queue => 'fork', :priority => 15)
|
||||
async(:write_hook)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue