delayed_job 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.2
1
+ 2.0.3
data/benchmarks.rb CHANGED
@@ -4,6 +4,8 @@ require 'logger'
4
4
  require 'delayed_job'
5
5
  require 'benchmark'
6
6
 
7
+ RAILS_ENV = 'test'
8
+
7
9
  Delayed::Worker.logger = Logger.new('/dev/null')
8
10
 
9
11
  BACKENDS = []
@@ -0,0 +1,23 @@
1
+ # an example Monit configuration file for delayed_job running multiple processes
2
+ #
3
+ # To use:
4
+ # 1. copy to /var/www/apps/{app_name}/shared/delayed_job.monitrc
5
+ # 2. replace {app_name} as appropriate
6
+ # 3. add this to your /etc/monit/monitrc
7
+ #
8
+ # include /var/www/apps/{app_name}/shared/delayed_job.monitrc
9
+
10
+ check process delayed_job_0
11
+ with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.0.pid
12
+ start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start -i 0"
13
+ stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 0"
14
+
15
+ check process delayed_job_1
16
+ with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.1.pid
17
+ start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start -i 1"
18
+ stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 1"
19
+
20
+ check process delayed_job_2
21
+ with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.2.pid
22
+ start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start -i 2"
23
+ stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 2"
data/delayed_job.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{delayed_job}
8
- s.version = "2.0.2"
8
+ s.version = "2.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brandon Keepers", "Tobias L\303\274tke"]
12
- s.date = %q{2010-04-08}
12
+ s.date = %q{2010-04-16}
13
13
  s.description = %q{Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks.
14
14
 
15
15
  This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job).}
@@ -25,6 +25,7 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
25
25
  "VERSION",
26
26
  "benchmarks.rb",
27
27
  "contrib/delayed_job.monitrc",
28
+ "contrib/delayed_job_multiple.monitrc",
28
29
  "delayed_job.gemspec",
29
30
  "generators/delayed_job/delayed_job_generator.rb",
30
31
  "generators/delayed_job/templates/migration.rb",
@@ -42,6 +43,7 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
42
43
  "lib/delayed/tasks.rb",
43
44
  "lib/delayed/worker.rb",
44
45
  "lib/delayed_job.rb",
46
+ "rails/init.rb",
45
47
  "recipes/delayed_job.rb",
46
48
  "spec/backend/active_record_job_spec.rb",
47
49
  "spec/backend/data_mapper_job_spec.rb",
data/init.rb CHANGED
@@ -1,5 +1 @@
1
- require 'delayed_job'
2
-
3
- config.after_initialize do
4
- Delayed::Worker.guess_backend
5
- end
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
@@ -8,7 +8,10 @@ module Delayed
8
8
 
9
9
  def initialize(args)
10
10
  @files_to_reopen = []
11
- @options = {:quiet => true}
11
+ @options = {
12
+ :quiet => true,
13
+ :pid_dir => "#{RAILS_ROOT}/tmp/pids"
14
+ }
12
15
 
13
16
  @worker_count = 1
14
17
 
@@ -31,6 +34,12 @@ module Delayed
31
34
  opts.on('-n', '--number_of_workers=workers', "Number of unique workers to spawn") do |worker_count|
32
35
  @worker_count = worker_count.to_i rescue 1
33
36
  end
37
+ opts.on('--pid-dir=DIR', 'Specifies an alternate directory in which to store the process ids.') do |dir|
38
+ @options[:pid_dir] = dir
39
+ end
40
+ opts.on('-i', '--identifier=n', 'A numeric identifier for the worker.') do |n|
41
+ @options[:identifier] = n
42
+ end
34
43
  end
35
44
  @args = opts.parse!(args)
36
45
  end
@@ -42,33 +51,41 @@ module Delayed
42
51
  @files_to_reopen << file unless file.closed?
43
52
  end
44
53
 
45
- dir = "#{RAILS_ROOT}/tmp/pids"
54
+ dir = @options[:pid_dir]
46
55
  Dir.mkdir(dir) unless File.exists?(dir)
47
56
 
48
- worker_count.times do |worker_index|
49
- process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}"
50
- Daemons.run_proc(process_name, :dir => dir, :dir_mode => :normal, :ARGV => @args) do |*args|
51
- run process_name
57
+ if @worker_count > 1 && @options[:identifier]
58
+ raise ArgumentError, 'Cannot specify both --number-of-workers and --identifier'
59
+ elsif @worker_count == 1 && @options[:identifier]
60
+ process_name = "delayed_job.#{@options[:identifier]}"
61
+ run_process(process_name, dir)
62
+ else
63
+ worker_count.times do |worker_index|
64
+ process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}"
65
+ run_process(process_name, dir)
52
66
  end
53
67
  end
54
68
  end
55
69
 
70
+ def run_process(process_name, dir)
71
+ Daemons.run_proc(process_name, :dir => dir, :dir_mode => :normal, :ARGV => @args) do |*args|
72
+ run process_name
73
+ end
74
+ end
75
+
56
76
  def run(worker_name = nil)
57
77
  Dir.chdir(RAILS_ROOT)
58
78
 
59
79
  # Re-open file handles
60
80
  @files_to_reopen.each do |file|
61
81
  begin
62
- file.reopen File.join(RAILS_ROOT, 'log', 'delayed_job.log'), 'a+'
82
+ file.reopen file.path
63
83
  file.sync = true
64
84
  rescue ::Exception
65
85
  end
66
86
  end
67
87
 
68
- Delayed::Worker.logger = Rails.logger
69
- if Delayed::Worker.logger.respond_to? :auto_flushing=
70
- Delayed::Worker.logger.auto_flushing = true
71
- end
88
+ Delayed::Worker.logger = Logger.new(File.join(RAILS_ROOT, 'log', 'delayed_job.log'))
72
89
  Delayed::Worker.backend.after_fork
73
90
 
74
91
  worker = Delayed::Worker.new(@options)
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'delayed_job'
2
+
3
+ config.after_initialize do
4
+ Delayed::Worker.guess_backend
5
+ end
@@ -1,7 +1,9 @@
1
1
  require 'mongo_mapper'
2
2
 
3
- MongoMapper.connection = Mongo::Connection.new nil, nil, :logger => Delayed::Worker.logger
4
- MongoMapper.database = 'delayed_job'
3
+ MongoMapper.config = {
4
+ RAILS_ENV => {'database' => 'delayed_job'}
5
+ }
6
+ MongoMapper.connect RAILS_ENV
5
7
 
6
8
  unless defined?(Story)
7
9
  class Story
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,7 @@ require 'delayed_job'
8
8
  require 'sample_jobs'
9
9
 
10
10
  Delayed::Worker.logger = Logger.new('/tmp/dj.log')
11
+ RAILS_ENV = 'test'
11
12
 
12
13
  # determine the available backends
13
14
  BACKENDS = []
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 0
8
- - 2
9
- version: 2.0.2
8
+ - 3
9
+ version: 2.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brandon Keepers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-08 00:00:00 -04:00
18
+ date: 2010-04-16 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -157,6 +157,7 @@ files:
157
157
  - VERSION
158
158
  - benchmarks.rb
159
159
  - contrib/delayed_job.monitrc
160
+ - contrib/delayed_job_multiple.monitrc
160
161
  - delayed_job.gemspec
161
162
  - generators/delayed_job/delayed_job_generator.rb
162
163
  - generators/delayed_job/templates/migration.rb
@@ -174,6 +175,7 @@ files:
174
175
  - lib/delayed/tasks.rb
175
176
  - lib/delayed/worker.rb
176
177
  - lib/delayed_job.rb
178
+ - rails/init.rb
177
179
  - recipes/delayed_job.rb
178
180
  - spec/backend/active_record_job_spec.rb
179
181
  - spec/backend/data_mapper_job_spec.rb