delayed_job 1.8.3 → 1.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.3
1
+ 1.8.4
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 = "1.8.3"
8
+ s.version = "1.8.4"
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{2009-09-28}
12
+ s.date = %q{2009-10-06}
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
  s.email = %q{tobi@leetsoft.com}
15
15
  s.extra_rdoc_files = [
@@ -67,7 +67,7 @@ module Delayed
67
67
 
68
68
  Delayed::Worker.new(@options).start
69
69
  rescue => e
70
- logger.fatal e
70
+ Rails.logger.fatal e
71
71
  STDERR.puts e.message
72
72
  exit 1
73
73
  end
data/lib/delayed/job.rb CHANGED
@@ -65,10 +65,9 @@ module Delayed
65
65
  # Reschedule the job in the future (when a job fails).
66
66
  # Uses an exponential scale depending on the number of failed attempts.
67
67
  def reschedule(message, backtrace = [], time = nil)
68
- if self.attempts < MAX_ATTEMPTS
68
+ if (self.attempts += 1) < MAX_ATTEMPTS
69
69
  time ||= Job.db_time_now + (attempts ** 4) + 5
70
70
 
71
- self.attempts += 1
72
71
  self.run_at = time
73
72
  self.last_error = message + "\n" + backtrace.join("\n")
74
73
  self.unlock
@@ -3,6 +3,10 @@ module Delayed
3
3
  def send_later(method, *args)
4
4
  Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sym, args)
5
5
  end
6
+
7
+ def send_at(time, method, *args)
8
+ Delayed::Job.enqueue(Delayed::PerformableMethod.new(self, method.to_sym, args), 0, time)
9
+ end
6
10
 
7
11
  module ClassMethods
8
12
  def handle_asynchronously(method)
@@ -125,4 +125,26 @@ describe 'random ruby objects' do
125
125
  job.payload_object.perform.should == 'Once upon...'
126
126
  end
127
127
 
128
+ context "send_at" do
129
+ it "should queue a new job" do
130
+ lambda do
131
+ "string".send_at(1.hour.from_now, :length)
132
+ end.should change { Delayed::Job.count }.by(1)
133
+ end
134
+
135
+ it "should schedule the job in the future" do
136
+ time = 1.hour.from_now
137
+ job = "string".send_at(time, :length)
138
+ job.run_at.should == time
139
+ end
140
+
141
+ it "should store payload as PerformableMethod" do
142
+ job = "string".send_at(1.hour.from_now, :count, 'r')
143
+ job.payload_object.class.should == Delayed::PerformableMethod
144
+ job.payload_object.method.should == :count
145
+ job.payload_object.args.should == ['r']
146
+ job.payload_object.perform.should == 1
147
+ end
148
+ end
149
+
128
150
  end
data/spec/job_spec.rb CHANGED
@@ -152,29 +152,46 @@ describe Delayed::Job do
152
152
  lambda { job.payload_object.perform }.should raise_error(Delayed::DeserializationError)
153
153
  end
154
154
 
155
- it "should be failed if it failed more than MAX_ATTEMPTS times and we don't want to destroy jobs" do
156
- default = Delayed::Job.destroy_failed_jobs
157
- Delayed::Job.destroy_failed_jobs = false
158
-
159
- @job = Delayed::Job.create :payload_object => SimpleJob.new, :attempts => 50
160
- @job.reload.failed_at.should == nil
161
- @job.reschedule 'FAIL'
162
- @job.reload.failed_at.should_not == nil
163
-
164
- Delayed::Job.destroy_failed_jobs = default
165
- end
166
-
167
- it "should be destroyed if it failed more than MAX_ATTEMPTS times and we want to destroy jobs" do
168
- default = Delayed::Job.destroy_failed_jobs
169
- Delayed::Job.destroy_failed_jobs = true
170
-
171
- @job = Delayed::Job.create :payload_object => SimpleJob.new, :attempts => 50
172
- @job.should_receive(:destroy)
173
- @job.reschedule 'FAIL'
174
-
175
- Delayed::Job.destroy_failed_jobs = default
155
+ context "reschedule" do
156
+ before do
157
+ @job = Delayed::Job.create :payload_object => SimpleJob.new
158
+ end
159
+
160
+ context "and we want to destroy jobs" do
161
+ before do
162
+ Delayed::Job.destroy_failed_jobs = true
163
+ end
164
+
165
+ it "should be destroyed if it failed more than MAX_ATTEMPTS times" do
166
+ @job.should_receive(:destroy)
167
+ Delayed::Job::MAX_ATTEMPTS.times { @job.reschedule 'FAIL' }
168
+ end
169
+
170
+ it "should not be destroyed if failed fewer than MAX_ATTEMPTS times" do
171
+ @job.should_not_receive(:destroy)
172
+ (Delayed::Job::MAX_ATTEMPTS - 1).times { @job.reschedule 'FAIL' }
173
+ end
174
+ end
175
+
176
+ context "and we don't want to destroy jobs" do
177
+ before do
178
+ Delayed::Job.destroy_failed_jobs = false
179
+ end
180
+
181
+ it "should be failed if it failed more than MAX_ATTEMPTS times" do
182
+ @job.reload.failed_at.should == nil
183
+ Delayed::Job::MAX_ATTEMPTS.times { @job.reschedule 'FAIL' }
184
+ @job.reload.failed_at.should_not == nil
185
+ end
186
+
187
+ it "should not be failed if it failed fewer than MAX_ATTEMPTS times" do
188
+ (Delayed::Job::MAX_ATTEMPTS - 1).times { @job.reschedule 'FAIL' }
189
+ @job.reload.failed_at.should == nil
190
+ end
191
+
192
+ end
176
193
  end
177
-
194
+
178
195
  it "should fail after MAX_RUN_TIME" do
179
196
  @job = Delayed::Job.create :payload_object => LongRunningJob.new
180
197
  Delayed::Job.reserve_and_run_one_job(1.second)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-28 00:00:00 -04:00
13
+ date: 2009-10-06 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16