resque-forker 1.0.beta → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -2
- data/README.rdoc +4 -1
- data/lib/resque/forker.rb +26 -14
- data/resque-forker.gemspec +3 -4
- data/script/workers +4 -1
- metadata +12 -14
data/CHANGELOG
CHANGED
@@ -1,2 +1,10 @@
|
|
1
|
-
2010-
|
2
|
-
|
1
|
+
2010-08-11 v1.1 Accessible options.
|
2
|
+
|
3
|
+
Allows accessing options from forker.
|
4
|
+
Allows setting verbose and very_verbose options instead of being magically inferred.
|
5
|
+
Allows passing workload to fork! method as an option.
|
6
|
+
|
7
|
+
2010-08-03 v1.0 First release
|
8
|
+
|
9
|
+
2010-07-30 v1.0.beta
|
10
|
+
Extracted from Flowtown with permission
|
data/README.rdoc
CHANGED
@@ -34,10 +34,13 @@ Edit this to your needs and place it in script/workers:
|
|
34
34
|
forker.logger = Rails.logger
|
35
35
|
forker.workload = ["*"] * 4 # 4 workers on all queues
|
36
36
|
forker.user "www-data", "www-data" # don't run as root
|
37
|
+
forker.options.interval = 1
|
38
|
+
else
|
39
|
+
forker.options.verbose = true
|
37
40
|
end
|
38
41
|
end
|
39
42
|
# Stuff to do after forking a worker.
|
40
|
-
Resque.
|
43
|
+
Resque.before_first_fork do
|
41
44
|
ActiveRecord::Base.establish_connection
|
42
45
|
end
|
43
46
|
Resque.fork!
|
data/lib/resque/forker.rb
CHANGED
@@ -14,8 +14,10 @@ module Resque
|
|
14
14
|
# ActiveRecord::Base.connection.disconnect!
|
15
15
|
# forker.logger = Rails.logger
|
16
16
|
# forker.user "nobody", "nobody"
|
17
|
+
# forker.workload = ["*"] * 8
|
18
|
+
# forker.options.interval = 1
|
17
19
|
# end
|
18
|
-
# Resque.
|
20
|
+
# Resque.before_first_fork do
|
19
21
|
# ActiveRecord::Base.establish_connection
|
20
22
|
# end
|
21
23
|
#
|
@@ -27,14 +29,14 @@ module Resque
|
|
27
29
|
#
|
28
30
|
# All the forking action is handled by a single call:
|
29
31
|
# # Three workers, processing all queues
|
30
|
-
# Resque.fork! ["*"] * 3
|
32
|
+
# Resque.fork! :workload=>["*"] * 3
|
31
33
|
#
|
32
34
|
# The workload is specified as an array of lists of queues, that way you can
|
33
35
|
# decide how many workers to fork (length of the array) and give each worker
|
34
36
|
# different set of queues to work with. For example, to have four workers
|
35
37
|
# processing import queue, and only two of these also processing export queue:
|
36
38
|
#
|
37
|
-
#
|
39
|
+
# forker.workload = ["import,export", "import"] * 2
|
38
40
|
#
|
39
41
|
# Once the process is up and running, you control it by sending signals:
|
40
42
|
# - kill -QUIT -- Quit gracefully
|
@@ -58,10 +60,14 @@ module Resque
|
|
58
60
|
# exec script/workers
|
59
61
|
# respawn
|
60
62
|
class Forker
|
63
|
+
|
64
|
+
Options = Struct.new(:verbose, :very_verbose, :interval, :terminate)
|
65
|
+
|
61
66
|
def initialize(options = nil)
|
62
|
-
|
63
|
-
@logger =
|
64
|
-
@workload = ["*"]
|
67
|
+
options ||= {}
|
68
|
+
@logger = options[:logger] || Logger.new($stderr)
|
69
|
+
@workload = options[:workload] || ["*"]
|
70
|
+
@options = Options[*options.values_at(*Options.members)]
|
65
71
|
@children = []
|
66
72
|
begin
|
67
73
|
require "system_timer"
|
@@ -79,6 +85,9 @@ module Resque
|
|
79
85
|
# Defaults to stderr, but you may want to point this at Rails logger.
|
80
86
|
attr_accessor :logger
|
81
87
|
|
88
|
+
# Most options can be changed from the Resque.setup hook. See Options.
|
89
|
+
attr_reader :options
|
90
|
+
|
82
91
|
# Run and never return.
|
83
92
|
def run
|
84
93
|
@logger.info "** Running as #{Process.pid}"
|
@@ -149,9 +158,9 @@ module Resque
|
|
149
158
|
# Run and never return.
|
150
159
|
def run_worker(queues)
|
151
160
|
worker = Resque::Worker.new(*queues.split(","))
|
152
|
-
worker.verbose =
|
153
|
-
worker.very_verbose =
|
154
|
-
worker.work(
|
161
|
+
worker.verbose = options.verbose
|
162
|
+
worker.very_verbose = options.very_verbose
|
163
|
+
worker.work(options.interval || 5) # interval, will block
|
155
164
|
end
|
156
165
|
|
157
166
|
# Stop child processes and run any teardown action.
|
@@ -166,7 +175,7 @@ module Resque
|
|
166
175
|
end
|
167
176
|
reap_children
|
168
177
|
if teardown = Resque.teardown
|
169
|
-
@timeout.call
|
178
|
+
@timeout.call options.terminate || 5 do
|
170
179
|
begin
|
171
180
|
teardown.call self
|
172
181
|
rescue Exception
|
@@ -224,9 +233,12 @@ module Resque
|
|
224
233
|
# - :logger -- Which Logger to use (default logger to stdout)
|
225
234
|
# - :interval -- Processing interval (default to 5 seconds)
|
226
235
|
# - :terminate -- Timeout running teardown block (default to 5 seconds)
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
236
|
+
# - :verbose -- Be verbose.
|
237
|
+
# - :very_verbose -- Make :verbose look quiet.
|
238
|
+
# - :workload -- The initial workload.
|
239
|
+
#
|
240
|
+
# You can also set these options from the Resque.setup hook.
|
241
|
+
def fork!(options = nil)
|
242
|
+
Resque::Forker.new(options).run
|
231
243
|
end
|
232
244
|
end
|
data/resque-forker.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "resque-forker"
|
3
|
-
spec.version = "1.0
|
3
|
+
spec.version = "1.1.0"
|
4
4
|
spec.author = "Assaf Arkin"
|
5
5
|
spec.email = "assaf@labnotes.org"
|
6
|
-
spec.homepage = "http://github.com/
|
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
|
|
@@ -11,8 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.has_rdoc = true
|
13
13
|
spec.extra_rdoc_files = "README.rdoc", "CHANGELOG"
|
14
|
-
spec.rdoc_options = "--title", "Resque Forker #{spec.version}", "--main", "README.rdoc",
|
15
|
-
"--webcvs", "http://github.com/assaf/#{spec.name}"
|
14
|
+
spec.rdoc_options = "--title", "Resque Forker #{spec.version}", "--main", "README.rdoc", "--webcvs", spec.homepage
|
16
15
|
|
17
16
|
spec.required_ruby_version = '>= 1.8.7'
|
18
17
|
spec.add_dependency "resque"
|
data/script/workers
CHANGED
@@ -9,10 +9,13 @@ Resque.setup do |forker|
|
|
9
9
|
forker.logger = Rails.logger
|
10
10
|
forker.workload = ["*"] * 4 # 4 workers on all queues
|
11
11
|
forker.user "www-data", "www-data" # don't run as root
|
12
|
+
forker.options.interval = 1
|
13
|
+
else
|
14
|
+
forker.options.verbose = true
|
12
15
|
end
|
13
16
|
end
|
14
17
|
# Stuff to do after forking a worker.
|
15
|
-
Resque.
|
18
|
+
Resque.before_first_fork do
|
16
19
|
ActiveRecord::Base.establish_connection
|
17
20
|
end
|
18
21
|
Resque.fork!
|
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.beta
|
10
|
+
version: 1.1.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-
|
18
|
+
date: 2010-08-11 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -50,17 +50,17 @@ files:
|
|
50
50
|
- Rakefile
|
51
51
|
- resque-forker.gemspec
|
52
52
|
has_rdoc: true
|
53
|
-
homepage: http://github.com/
|
53
|
+
homepage: http://github.com/flowtown/resque-forker
|
54
54
|
licenses: []
|
55
55
|
|
56
56
|
post_install_message: ""
|
57
57
|
rdoc_options:
|
58
58
|
- --title
|
59
|
-
- Resque Forker 1.0
|
59
|
+
- Resque Forker 1.1.0
|
60
60
|
- --main
|
61
61
|
- README.rdoc
|
62
62
|
- --webcvs
|
63
|
-
- http://github.com/
|
63
|
+
- http://github.com/flowtown/resque-forker
|
64
64
|
require_paths:
|
65
65
|
- lib
|
66
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -77,14 +77,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
78
|
none: false
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
hash:
|
82
|
+
hash: 3
|
83
83
|
segments:
|
84
|
-
-
|
85
|
-
|
86
|
-
- 1
|
87
|
-
version: 1.3.1
|
84
|
+
- 0
|
85
|
+
version: "0"
|
88
86
|
requirements: []
|
89
87
|
|
90
88
|
rubyforge_project:
|