resque-forker 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,10 +1,30 @@
1
+ 2010-09-06 v1.2 Capistrano task and script/trigger
2
+
3
+ Added Capistrano tasks for pausing, resuming, reloading and listing worker
4
+ processes. To use, add this at the top of your Capfile:
5
+
6
+ require "resque/capistrano"
7
+
8
+ And associate your worker instances with the role :worker. The workers will be
9
+ reloaded after deploy:restart, suspended before deploy:web:disable and resumed
10
+ after deploy:web:enable.
11
+
12
+ Added script/trigger to queue jobs from the command line (but more likely
13
+ cronjob or upstart).
14
+
15
+ Improved script/worker and /etc/init/workers based on real life experiences.
16
+ And real life production deploys, let me tell you, can be a PITA.
17
+
18
+
1
19
  2010-08-11 v1.1 Accessible options.
2
20
 
3
21
  Allows accessing options from forker.
4
22
  Allows setting verbose and very_verbose options instead of being magically inferred.
5
23
  Allows passing workload to fork! method as an option.
6
24
 
25
+
7
26
  2010-08-03 v1.0 First release
8
27
 
28
+
9
29
  2010-07-30 v1.0.beta
10
30
  Extracted from Flowtown with permission
data/README.rdoc CHANGED
@@ -1,6 +1,7 @@
1
1
  = Resque::Forker
2
2
 
3
- Super awesome forking action for Resque workers.
3
+ Super awesome forking action for {Resque}[http://github.com/defunkt/resque]
4
+ workers.
4
5
 
5
6
  == Forking Workers
6
7
 
@@ -24,17 +25,21 @@ queues) to process.
24
25
  Edit this to your needs and place it in script/workers:
25
26
 
26
27
  #!/usr/bin/env ruby
28
+ # If using Bundler, you might need to uncomment next two lines
29
+ #require "bundler"
30
+ #Bundler.setup
27
31
  require "resque/forker"
28
32
 
29
33
  # Load the application.
30
34
  Resque.setup do |forker|
31
- require File.dirname(__FILE__) + "/../config/environment"
35
+ $:.unshift File.dirname(__FILE__) + "/.." # Makes 1.9.2 happy
36
+ require "config/environment"
32
37
  ActiveRecord::Base.connection.disconnect!
38
+ forker.options.interval = 1
33
39
  if Rails.env.production?
34
40
  forker.logger = Rails.logger
35
41
  forker.workload = ["*"] * 4 # 4 workers on all queues
36
42
  forker.user "www-data", "www-data" # don't run as root
37
- forker.options.interval = 1
38
43
  else
39
44
  forker.options.verbose = true
40
45
  end
@@ -90,18 +95,20 @@ Of course, you want the workers to start after reboot and each way to control
90
95
  them. Read on how to use Resque::Forker with Upstart.
91
96
 
92
97
 
93
- == Using Upstart and Capistrano
98
+ == Using Upstart
94
99
 
95
- If you're running a recent release of Ubuntu, you can get Upstart to manage your
96
- workers.
100
+ If you're running a recent release of Ubuntu, you can get
101
+ {Upstart}[http://upstart.ubuntu.com/] to manage your workers.
97
102
 
98
103
  Edit this to your needs and place it in /etc/init/workers:
99
104
 
100
105
  start on runlevel [2345]
101
106
  stop on runlevel [06]
107
+
102
108
  chdir /var/www/myapp/current
103
109
  env RAILS_ENV=production
104
110
  exec script/workers
111
+
105
112
  respawn
106
113
 
107
114
  After reading this, Upstart to make sure your workers are always up and running.
@@ -115,36 +122,50 @@ To start, stop, check status and reload:
115
122
  $ reload workers
116
123
 
117
124
  You need to be root to start/stop the workers. However, if you change ownership
118
- of the workers (see fork.user above) you can reload them as that user. You can
119
- do something like this in your Capfile:
120
-
121
- namespace :workers do
122
- task :pause do
123
- run "status workers | cut -d ' ' -f 4 | xargs kill -USR2"
124
- end
125
- task :resume do
126
- run "status workers | cut -d ' ' -f 4 | xargs kill -CONT"
127
- end
128
- task :reload do
129
- run "reload workers"
130
- end
131
- end
132
- after "deploy:update_code", "workers:reload"
125
+ of the workers (see fork.user above) you can reload them as that user.
133
126
 
134
127
  Because of the way Upstart works, there is no need for PID file or running as
135
128
  daemon. Yay for sane process supervisors! When you reload workers,
136
129
  Resque::Forker reloads itself (and the application) while keeping the same PID.
137
130
 
138
131
 
132
+ == Using Capistrano
133
+
134
+ Make sure to require "resque/capistrano" at the top of your
135
+ {Capfile}[http://www.capify.org/] and associate worker instances with the roles
136
+ :worker.
137
+
138
+ You now have four new task:
139
+ * workers:pid -- Lists PID and additional information for all worker processes.
140
+ * workers:suspend -- Suspends all workers (do not pick any new jobs).
141
+ * workers:resume -- Resumes all workers.
142
+ * workers:reload -- Reloads all workers.
143
+
144
+ For convenience, the workers:reload task is wired to execute after
145
+ deploy:restart. In addition, workers:suspend executes before
146
+ deploy:web:disable, and workers:resume after deploy:web:enable.
147
+
148
+
139
149
  == Troubleshooting
140
150
 
141
- If you're using Bundler, you might need to run the script using:
151
+ If you're using {Bundler}[http://gembundler.com/], you might need to run the
152
+ script {like this}[http://gembundler.com/man/bundle-exec.1.html]:
142
153
 
143
154
  exec bundle exec script/workers
144
155
 
145
- If you're using RVM and Bundler, you might need to create a wrapper and use it:
156
+ If you're using {RVM}[http://rvm.beginrescueend.com/] and have a system-wide
157
+ install, you'll want to {create a
158
+ wrapper}[http://rvm.beginrescueend.com/deployment/best-practices/], for
159
+ example:
160
+
161
+ $ rvm wrapper 1.9.2 app ruby
162
+
163
+ Then run the script using the wrapper:
164
+
165
+ exec app_ruby script/workers
146
166
 
147
- exec run_bundle script/workers
167
+ If you're using RVM and Bundler, don't forget to uncomment the relevant lines in
168
+ script/workers.
148
169
 
149
170
  The point is, when the script starts it will expect both resque and
150
171
  resque-forker must be available for loading (that typically means GEMPATH).
@@ -163,4 +184,4 @@ that doesn't have your regular account settings:
163
184
 
164
185
  == Credits
165
186
 
166
- Copyright (c) 2010 Flowtown, Inc.
187
+ Copyright (c) 2010 {Flowtow, Inc}[http://flowtown.com].
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
- spec = Gem::Specification.load(File.expand_path("resque-forker.gemspec", File.dirname(__FILE__)))
1
+ require "yard"
2
+
3
+ spec = Gem::Specification.load(Dir["*.gemspec"].first)
2
4
 
3
5
  desc "Build the Gem"
4
6
  task :build do
@@ -20,3 +22,7 @@ task :push=>["build"] do
20
22
  puts "Building and pushing gem .."
21
23
  sh "gem push #{spec.name}-#{spec.version}.gem"
22
24
  end
25
+
26
+ YARD::Rake::YardocTask.new do |doc|
27
+ doc.files = FileList["lib/**/*.rb"]
28
+ end
@@ -0,0 +1,31 @@
1
+ # Capistrano task for Resque::Forker.
2
+ #
3
+ # To use these tasks, require "resque/capistrano" at the top of the Capfile and
4
+ # associate your woker instances with the role 'workers'.
5
+ #
6
+ # Performs workers:reload after deploy:restart, workers:suspend before
7
+ # deploy:web:disable and workers:resume after deploy:web:enable.
8
+ Capistrano::Configuration.instance(:must_exist).load do
9
+ after "deploy:restart", "workers:reload"
10
+ before "deploy:web:disable", "workers:suspend"
11
+ after "deploy:web:enabled", "workers:resume"
12
+
13
+ namespace :workers do
14
+ desc "Suspend all resque workers"
15
+ task :suspend, :roles=>:workers do
16
+ run "status workers | cut -d ' ' -f 4 | xargs kill -USR2"
17
+ end
18
+ desc "Resume all workers that have been paused"
19
+ task :resume, :roles=>:workers do
20
+ run "status workers | cut -d ' ' -f 4 | xargs kill -CONT"
21
+ end
22
+ desc "Reload all workers"
23
+ task :reload, :roles=>:workers do
24
+ run "reload workers"
25
+ end
26
+ desc "List Resque processes"
27
+ task :pids, :roles=>:workers do
28
+ puts capture("ps aux | grep [r]esque")
29
+ end
30
+ end
31
+ end
data/lib/resque/forker.rb CHANGED
@@ -10,7 +10,8 @@ module Resque
10
10
  #
11
11
  # To use this library, wrap your setup and teardown blocks:
12
12
  # Resque.setup do |forker|
13
- # require File.dirname(__FILE__) + "/../config/environment"
13
+ # $:.unshift File.dirname(__FILE__) + "/.."
14
+ # require "config/environment"
14
15
  # ActiveRecord::Base.connection.disconnect!
15
16
  # forker.logger = Rails.logger
16
17
  # forker.user "nobody", "nobody"
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "resque-forker"
3
- spec.version = "1.1.0"
3
+ spec.version = "1.2.0"
4
4
  spec.author = "Assaf Arkin"
5
5
  spec.email = "assaf@labnotes.org"
6
6
  spec.homepage = "http://github.com/flowtown/resque-forker"
7
7
  spec.summary = "Super awesome forking action for Resque workers"
8
8
  spec.post_install_message = ""
9
9
 
10
- spec.files = Dir["{lib,script}/**/*", "CHANGELOG", "MIT-LICENSE", "README.rdoc", "Rakefile", "resque-forker.gemspec"]
10
+ spec.files = Dir["{lib,script}/**/*", "CHANGELOG", "MIT-LICENSE", "README.rdoc", "Rakefile", "*.gemspec"]
11
11
 
12
12
  spec.has_rdoc = true
13
13
  spec.extra_rdoc_files = "README.rdoc", "CHANGELOG"
data/script/trigger ADDED
@@ -0,0 +1,11 @@
1
+ #!ruby
2
+ # Run like this:
3
+ # run /var/app/current/script/trigger <queue> <ClassName> <arg1> ...
4
+
5
+ # Go here to start from app's root directory.
6
+ Dir.chdir File.expand_path(File.dirname(__FILE__) + "/..")
7
+ # If using Bundler, you might need to uncomment next two lines
8
+ #require "bundler"
9
+ #Bundler.setup
10
+ require "resque"
11
+ Resque::Job.create *ARGV
data/script/workers CHANGED
@@ -1,15 +1,21 @@
1
- #!/usr/bin/env ruby
1
+ #!ruby
2
+ # Go here to start from app's root directory.
3
+ Dir.chdir File.expand_path(File.dirname(__FILE__) + "/..")
4
+ # If using Bundler, you might need to uncomment next two lines
5
+ #require "bundler"
6
+ #Bundler.setup
2
7
  require "resque/forker"
3
8
 
4
9
  # Load the application.
5
10
  Resque.setup do |forker|
6
- require File.dirname(__FILE__) + "/../config/environment"
11
+ $:.unshift Dir.pwd # Makes 1.9.2 happy
12
+ require "config/environment"
7
13
  ActiveRecord::Base.connection.disconnect!
14
+ forker.options.interval = 1
8
15
  if Rails.env.production?
9
16
  forker.logger = Rails.logger
10
17
  forker.workload = ["*"] * 4 # 4 workers on all queues
11
18
  forker.user "www-data", "www-data" # don't run as root
12
- forker.options.interval = 1
13
19
  else
14
20
  forker.options.verbose = true
15
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-forker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Assaf Arkin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-11 00:00:00 -07:00
18
+ date: 2010-09-06 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,9 @@ extra_rdoc_files:
42
42
  - README.rdoc
43
43
  - CHANGELOG
44
44
  files:
45
+ - lib/resque/capistrano.rb
45
46
  - lib/resque/forker.rb
47
+ - script/trigger
46
48
  - script/workers
47
49
  - CHANGELOG
48
50
  - MIT-LICENSE
@@ -56,7 +58,7 @@ licenses: []
56
58
  post_install_message: ""
57
59
  rdoc_options:
58
60
  - --title
59
- - Resque Forker 1.1.0
61
+ - Resque Forker 1.2.0
60
62
  - --main
61
63
  - README.rdoc
62
64
  - --webcvs