resque-pool 0.0.5 → 0.0.7

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 CHANGED
@@ -2,37 +2,41 @@ Resque Pool
2
2
  ===========
3
3
 
4
4
  Resque pool is a simple library for managing a pool of resque workers. Given a
5
- configuration hash or a config file (resque-pool.yml or
6
- config/resque-pool.yml), it will manage your workers for you, starting up the
7
- appropriate number of workers for each.
5
+ a config file (`resque-pool.yml` or `config/resque-pool.yml`) or a config hash,
6
+ it will manage your workers for you, starting up the appropriate number of
7
+ workers for each.
8
8
 
9
9
  Benefits
10
10
  ---------
11
11
 
12
12
  * Less memory consumption - If you are using Ruby Enterprise Edition, or any
13
- ruby with copy-on-write safe garbage collection, this will save you a lot of
14
- memory when you managing many workers.
15
- * Simpler (less) config - If you are using monit or god or an init script to
16
- start up your workers, you can simply start up one pool, and it will manage
17
- your workers for you.
13
+ ruby with copy-on-write safe garbage collection, this could save you a lot of
14
+ memory when you are managing many workers.
15
+ * Simpler (less) config - If you are using monit or an init script to start up
16
+ your workers, you can start up one pool, and it will manage your workers for
17
+ you.
18
18
  * Faster startup - if you are starting many workers at once, you would normally
19
19
  have them competing for CPU as they load their environments. Resque-pool can
20
- load the environment once, and almost immediately fork all of your workers.
20
+ load the environment once and almost instantaneously fork all of the workers.
21
21
 
22
22
  How to use
23
23
  -----------
24
24
 
25
- To configure resque-pool, you can either set `Resque::Pool.config` to a hash in
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.
25
+ To configure resque-pool, you can use either `resque-pool.yml` or
26
+ `config/resque-pool.yml`. To use resque-pool, require its rake tasks in your
27
+ rake file, and call the resque:pool task.
29
28
 
30
- For example, to use resque-pool with rails, in `config/resque-pool.yml`:
29
+ The YAML file supports both using root level defaults as well as environment
30
+ specific overrides. For example, to use resque-pool with rails, in
31
+ `config/resque-pool.yml`:
31
32
 
32
33
  foo: 1
33
34
  bar: 2
34
35
  "foo,bar,baz": 4
35
36
 
37
+ production:
38
+ "foo,bar,baz": 10
39
+
36
40
  and in `lib/tasks/resque.rake`:
37
41
 
38
42
  require 'resque/pool/tasks'
@@ -45,9 +49,6 @@ and in `lib/tasks/resque.rake`:
45
49
 
46
50
  # preload the rails environment in the pool master
47
51
  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}
50
-
51
52
  # close any sockets or files in pool master
52
53
  ActiveRecord::Base.connection.disconnect!
53
54
 
@@ -127,10 +128,21 @@ TODO
127
128
 
128
129
  * do appropriate logging (e.g. all to one logfile, each queue to its own
129
130
  logfile, or each worker to its own logfile). Logfile location must be
130
- configurable.
131
- * (optionally) daemonize, setting a PID file somewhere
131
+ configurable, but default to `log/resque-pool.log`. Of course, since resque
132
+ "logs" by writing to $stdout, this is really no more than redirecting stdout
133
+ to the appropriate logfile.
134
+ * (optionally) daemonize, setting a PID file somewhere. configurable, of
135
+ course, but default to `tmp/pids/resque-pool.pid`.
132
136
  * recover gracefully from a malformed config file (on startup and HUP)
133
- * figure out a good way to test this (preferably via cucumber or rspec)
137
+ * procline for malformed config file, graceful shutdown... and other states?
138
+ * figure out a good automated way to test this (cucumber or rspec?)
134
139
  * clean up the code (I stole most of it from unicorn, and it's still a bit
135
- bastardized)
136
- * web interface for adding and removing workers (etc)
140
+ bastardized); excessive use of vim foldmarkers are a code smell.
141
+ * rdoc
142
+ * incorporate resque-batchworker features? (v2.0)
143
+ * web interface for adding and removing workers (etc) (v2.0)
144
+
145
+ Contributors
146
+ -------------
147
+
148
+ * John Schult (config file can be split by environment)
data/lib/resque/pool.rb CHANGED
@@ -50,13 +50,9 @@ module Resque
50
50
  # Config: class methods to start up the pool using the default config {{{
51
51
 
52
52
  @config_files = ["resque-pool.yml", "config/resque-pool.yml"]
53
- class << self; attr_accessor :config, :config_files; end
53
+ class << self; attr_accessor :config_files; end
54
54
  def self.load_default_config
55
- if @config
56
- @config
57
- else
58
- @config_files.detect { |f| File.exist?(f) }
59
- end
55
+ @config_files.detect { |f| File.exist?(f) }
60
56
  end
61
57
 
62
58
  def self.run
@@ -69,24 +65,35 @@ module Resque
69
65
  # }}}
70
66
  # Config: load config and config file {{{
71
67
 
72
- def load_config_from_file
73
- return unless @pool_config_file
74
- log "**** loading config from #{@pool_config_file}"
75
- @config = YAML.load_file(@pool_config_file)
76
- end
77
-
78
68
  def init_config(config)
79
69
  unless config
80
70
  raise ArgumentError,
81
71
  "No configuration found. Please setup config/resque-pool.yml"
82
72
  end
83
73
  if config.kind_of? String
84
- @pool_config_file = config.to_s
85
- load_config_from_file
74
+ @config_file = config.to_s
86
75
  else
87
76
  @config = config.dup
88
77
  end
89
- log "**** config: #{@config.inspect}"
78
+ load_config
79
+ end
80
+
81
+ def load_config
82
+ if @config_file
83
+ @config = YAML.load_file(@config_file)
84
+ end
85
+ if config_environment
86
+ config.merge!(@config[config_environment])
87
+ end
88
+ config.delete_if {|key, value| value.is_a? Hash }
89
+ end
90
+
91
+ def config_environment
92
+ if defined? RAILS_ENV
93
+ RAILS_ENV
94
+ else
95
+ ENV['RACK_ENV'] || ENV['RAILS_ENV'] || ENV['RESQUE_ENV']
96
+ end
90
97
  end
91
98
 
92
99
  # }}}
@@ -139,7 +146,7 @@ module Resque
139
146
  signal_all_workers(signal)
140
147
  when :HUP
141
148
  log "HUP: reload config file"
142
- load_config_from_file
149
+ load_config
143
150
  maintain_worker_count
144
151
  when :WINCH
145
152
  log "WINCH: gracefully stopping all workers"
@@ -17,7 +17,7 @@ class Resque::Pool
17
17
  end
18
18
 
19
19
  # this entire method (except for one line) is copied and pasted from
20
- # resque-1.9.9. If shutdown were used as a method (attr_reader) rather
20
+ # resque-1.9.10. If shutdown were used as a method (attr_reader) rather
21
21
  # than an instance variable, I wouldn't need to reduplicate this. :-(
22
22
  #
23
23
  # hopefully I can get defunkt to accept my patch for this.
@@ -34,7 +34,7 @@ class Resque::Pool
34
34
 
35
35
  if not @paused and job = reserve
36
36
  log "got: #{job.inspect}"
37
- run_hook :before_fork
37
+ run_hook :before_fork, job
38
38
  working_on job
39
39
 
40
40
  if @child = fork
metadata CHANGED
@@ -1,22 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-pool
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - nicholas a. evans
14
- - Unicorn hackers
15
14
  autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-07-29 00:00:00 -04:00
18
+ date: 2010-08-16 00:00:00 -04:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -41,12 +40,12 @@ dependencies:
41
40
  requirements:
42
41
  - - "="
43
42
  - !ruby/object:Gem::Version
44
- hash: 33
43
+ hash: 39
45
44
  segments:
46
45
  - 1
47
46
  - 9
48
- - 9
49
- version: 1.9.9
47
+ - 10
48
+ version: 1.9.10
50
49
  type: :runtime
51
50
  version_requirements: *id002
52
51
  description: " quickly and easily fork a pool of resque workers,\n saving memory (w/REE) and monitoring their uptime\n"