resque-pool 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +30 -26
- data/lib/resque/pool/pooled_worker.rb +2 -2
- data/lib/resque/pool/tasks.rb +10 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -23,9 +23,9 @@ How to use
|
|
23
23
|
-----------
|
24
24
|
|
25
25
|
To configure resque-pool, you can either set `Resque::Pool.config` to a hash in
|
26
|
-
your `resque:setup` or you can set the same config in either
|
27
|
-
or `config/resque-pool.yml`. To use resque-pool, require its
|
28
|
-
your rake file, and call the resque:pool task.
|
26
|
+
your `resque:pool:setup` or you can set the same config in either
|
27
|
+
`resque-pool.yml` or `config/resque-pool.yml`. To use resque-pool, require its
|
28
|
+
rake tasks in your rake file, and call the resque:pool task.
|
29
29
|
|
30
30
|
For example, to use resque-pool with rails, in `config/resque-pool.yml`:
|
31
31
|
|
@@ -36,43 +36,47 @@ For example, to use resque-pool with rails, in `config/resque-pool.yml`:
|
|
36
36
|
and in `lib/tasks/resque.rake`:
|
37
37
|
|
38
38
|
require 'resque/pool/tasks'
|
39
|
-
namespace :resque do
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
# this task will get called before resque:pool:setup
|
41
|
+
# preload the rails environment in the pool master
|
42
|
+
task "resque:setup" => :environment do
|
43
|
+
# generic worker setup, e.g. Hoptoad for failed jobs
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
# preload the rails environment in the pool master
|
47
|
+
task "resque:pool:setup" do
|
48
|
+
# it's better to use a config file, but you can also config here:
|
49
|
+
# Resque::Pool.config = {"foo" => 1, "bar" => 1}
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
ActiveRecord::Base.establish_connection
|
52
|
-
end
|
51
|
+
# close any sockets or files in pool master
|
52
|
+
ActiveRecord::Base.connection.disconnect!
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
# for every single job.
|
54
|
+
# and re-open them in the resque worker parent
|
55
|
+
Resque::Pool.after_prefork do |job|
|
56
|
+
ActiveRecord::Base.establish_connection
|
58
57
|
end
|
58
|
+
|
59
|
+
# you could also re-open them in the resque worker child, using
|
60
|
+
# Resque.after_fork, but that probably isn't necessary, and
|
61
|
+
# Resque::Pool.after_prefork should be faster, since it won't run
|
62
|
+
# for every single job.
|
59
63
|
end
|
60
64
|
|
61
65
|
Then you can start the queues via:
|
62
66
|
|
63
|
-
rake resque:pool RAILS_ENV=production
|
67
|
+
rake resque:pool RAILS_ENV=production VERBOSE=1
|
64
68
|
|
65
69
|
This will start up seven worker processes, one each looking exclusively at each
|
66
70
|
of the foo, bar, and baz queues, and four workers looking at all queues in
|
67
71
|
priority. This is similar to if you ran the following:
|
68
72
|
|
69
|
-
rake resque:
|
70
|
-
rake resque:
|
71
|
-
rake resque:
|
72
|
-
rake resque:
|
73
|
-
rake resque:
|
74
|
-
rake resque:
|
75
|
-
rake resque:
|
73
|
+
rake resque:work RAILS_ENV=production VERBOSE=1 QUEUES=foo
|
74
|
+
rake resque:work RAILS_ENV=production VERBOSE=1 QUEUES=bar
|
75
|
+
rake resque:work RAILS_ENV=production VERBOSE=1 QUEUES=bar
|
76
|
+
rake resque:work RAILS_ENV=production VERBOSE=1 QUEUES=foo,bar,baz
|
77
|
+
rake resque:work RAILS_ENV=production VERBOSE=1 QUEUES=foo,bar,baz
|
78
|
+
rake resque:work RAILS_ENV=production VERBOSE=1 QUEUES=foo,bar,baz
|
79
|
+
rake resque:work RAILS_ENV=production VERBOSE=1 QUEUES=foo,bar,baz
|
76
80
|
|
77
81
|
Resque already forks for its own child processes, giving two levels. The pool
|
78
82
|
master will stay around monitoring the resque worker parents, giving three
|
@@ -12,7 +12,7 @@ class Resque::Pool
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# this allows us to shutdown
|
15
|
-
def shutdown
|
15
|
+
def shutdown?
|
16
16
|
@shutdown || pool_master_has_gone_away?
|
17
17
|
end
|
18
18
|
|
@@ -29,7 +29,7 @@ class Resque::Pool
|
|
29
29
|
|
30
30
|
loop do
|
31
31
|
#### THIS IS THE ONLY LINE THAT IS CHANGED
|
32
|
-
break if shutdown
|
32
|
+
break if shutdown?
|
33
33
|
#### THAT WAS THE ONLY LINE THAT WAS CHANGED
|
34
34
|
|
35
35
|
if not @paused and job = reserve
|
data/lib/resque/pool/tasks.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require 'resque/tasks'
|
3
|
+
require 'resque/pool'
|
2
4
|
|
3
5
|
namespace :resque do
|
6
|
+
|
7
|
+
desc "resque worker config (not pool related). e.g. hoptoad"
|
4
8
|
task :setup
|
5
9
|
|
10
|
+
namespace :pool do
|
11
|
+
"resque pool config. e.g. after_prefork connection handling"
|
12
|
+
task :setup
|
13
|
+
end
|
14
|
+
|
6
15
|
desc "Launch a pool of resque workers"
|
7
|
-
task :pool => :setup do
|
8
|
-
require 'resque/pool'
|
16
|
+
task :pool => %w[resque:setup resque:pool:setup] do
|
9
17
|
Resque::Pool.run
|
10
18
|
end
|
11
19
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- nicholas a. evans
|