delayed_job_unique_key 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/delayed_job_unique_key.rb +8 -0
- data/lib/delayed_job_unique_key/active_record_job.rb +12 -0
- data/lib/delayed_job_unique_key/base.rb +52 -0
- data/lib/delayed_job_unique_key/version.rb +3 -0
- data/lib/generators/delayed_job_unique_key/install_generator.rb +17 -0
- data/lib/generators/delayed_job_unique_key/templates/add_unique_key_migration.rb +11 -0
- metadata +63 -174
- data/MIT-LICENSE +0 -20
- data/README.textile +0 -246
- data/contrib/delayed_job.monitrc +0 -14
- data/contrib/delayed_job_multiple.monitrc +0 -23
- data/lib/delayed/backend/base.rb +0 -152
- data/lib/delayed/backend/shared_spec.rb +0 -566
- data/lib/delayed/command.rb +0 -101
- data/lib/delayed/deserialization_error.rb +0 -4
- data/lib/delayed/lifecycle.rb +0 -84
- data/lib/delayed/message_sending.rb +0 -54
- data/lib/delayed/performable_mailer.rb +0 -21
- data/lib/delayed/performable_method.rb +0 -33
- data/lib/delayed/plugin.rb +0 -15
- data/lib/delayed/plugins/clear_locks.rb +0 -15
- data/lib/delayed/psych_ext.rb +0 -75
- data/lib/delayed/railtie.rb +0 -16
- data/lib/delayed/recipes.rb +0 -50
- data/lib/delayed/serialization/active_record.rb +0 -19
- data/lib/delayed/syck_ext.rb +0 -34
- data/lib/delayed/tasks.rb +0 -11
- data/lib/delayed/worker.rb +0 -222
- data/lib/delayed/yaml_ext.rb +0 -10
- data/lib/delayed_job.rb +0 -22
- data/lib/generators/delayed_job/delayed_job_generator.rb +0 -11
- data/lib/generators/delayed_job/templates/script +0 -5
- data/recipes/delayed_job.rb +0 -1
- data/spec/autoloaded/clazz.rb +0 -7
- data/spec/autoloaded/instance_clazz.rb +0 -6
- data/spec/autoloaded/instance_struct.rb +0 -6
- data/spec/autoloaded/struct.rb +0 -7
- data/spec/delayed/backend/test.rb +0 -113
- data/spec/delayed/serialization/test.rb +0 -0
- data/spec/fixtures/bad_alias.yml +0 -1
- data/spec/lifecycle_spec.rb +0 -107
- data/spec/message_sending_spec.rb +0 -116
- data/spec/performable_mailer_spec.rb +0 -46
- data/spec/performable_method_spec.rb +0 -89
- data/spec/sample_jobs.rb +0 -75
- data/spec/spec_helper.rb +0 -45
- data/spec/test_backend_spec.rb +0 -13
- data/spec/worker_spec.rb +0 -19
- data/spec/yaml_ext_spec.rb +0 -41
File without changes
|
data/spec/fixtures/bad_alias.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
foo: *bar
|
data/spec/lifecycle_spec.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Delayed::Lifecycle do
|
4
|
-
let(:lifecycle) { Delayed::Lifecycle.new }
|
5
|
-
let(:callback) { lambda {|*args|} }
|
6
|
-
let(:arguments) { [1] }
|
7
|
-
let(:behavior) { mock(Object, :before! => nil, :after! => nil, :inside! => nil) }
|
8
|
-
let(:wrapped_block) { Proc.new { behavior.inside! } }
|
9
|
-
|
10
|
-
describe "before callbacks" do
|
11
|
-
before(:each) do
|
12
|
-
lifecycle.before(:execute, &callback)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should execute before wrapped block' do
|
16
|
-
callback.should_receive(:call).with(*arguments).ordered
|
17
|
-
behavior.should_receive(:inside!).ordered
|
18
|
-
lifecycle.run_callbacks :execute, *arguments, &wrapped_block
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "after callbacks" do
|
23
|
-
before(:each) do
|
24
|
-
lifecycle.after(:execute, &callback)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should execute after wrapped block' do
|
28
|
-
behavior.should_receive(:inside!).ordered
|
29
|
-
callback.should_receive(:call).with(*arguments).ordered
|
30
|
-
lifecycle.run_callbacks :execute, *arguments, &wrapped_block
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "around callbacks" do
|
35
|
-
before(:each) do
|
36
|
-
lifecycle.around(:execute) do |*args, &block|
|
37
|
-
behavior.before!
|
38
|
-
block.call(*args)
|
39
|
-
behavior.after!
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should before and after wrapped block' do
|
44
|
-
behavior.should_receive(:before!).ordered
|
45
|
-
behavior.should_receive(:inside!).ordered
|
46
|
-
behavior.should_receive(:after!).ordered
|
47
|
-
lifecycle.run_callbacks :execute, *arguments, &wrapped_block
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should execute multiple callbacks in order" do
|
51
|
-
behavior.should_receive(:one).ordered
|
52
|
-
behavior.should_receive(:two).ordered
|
53
|
-
behavior.should_receive(:three).ordered
|
54
|
-
|
55
|
-
lifecycle.around(:execute) { |*args, &block| behavior.one; block.call(*args) }
|
56
|
-
lifecycle.around(:execute) { |*args, &block| behavior.two; block.call(*args) }
|
57
|
-
lifecycle.around(:execute) { |*args, &block| behavior.three; block.call(*args) }
|
58
|
-
|
59
|
-
lifecycle.run_callbacks(:execute, *arguments, &wrapped_block)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should raise if callback is executed with wrong number of parameters" do
|
64
|
-
lifecycle.before(:execute, &callback)
|
65
|
-
expect { lifecycle.run_callbacks(:execute, 1,2,3) {} }.to raise_error(ArgumentError, /1 parameter/)
|
66
|
-
end
|
67
|
-
|
68
|
-
# # This is a spectacularly crappy way to test callbacks. What's a better way?
|
69
|
-
# describe 'arguments callbacks' do
|
70
|
-
# subject do
|
71
|
-
# class Testarguments < Delayed::arguments
|
72
|
-
# def before_execute; end
|
73
|
-
# def before_loop; end
|
74
|
-
# def before_perform; end
|
75
|
-
#
|
76
|
-
# set_callback :execute, :before, :before_execute
|
77
|
-
# set_callback :loop, :before, :before_loop
|
78
|
-
# set_callback :perform, :before, :before_perform
|
79
|
-
# end
|
80
|
-
#
|
81
|
-
# Testarguments.new.tap { |w| w.stop }
|
82
|
-
# end
|
83
|
-
#
|
84
|
-
# it "should trigger for execute event" do
|
85
|
-
# subject.should_receive(:before_execute).with()
|
86
|
-
# subject.start
|
87
|
-
# end
|
88
|
-
#
|
89
|
-
# it "should trigger for loop event" do
|
90
|
-
# subject.should_receive(:before_loop).with()
|
91
|
-
# subject.start
|
92
|
-
# end
|
93
|
-
#
|
94
|
-
# it "should trigger for perform event" do
|
95
|
-
# "foo".delay.length
|
96
|
-
# subject.should_receive(:before_perform).with()
|
97
|
-
# subject.start
|
98
|
-
# end
|
99
|
-
# end
|
100
|
-
#
|
101
|
-
# describe 'job callbacks' do
|
102
|
-
# it "should trigger for enqueue event" do
|
103
|
-
# pending 'figure out how to test this'
|
104
|
-
# end
|
105
|
-
# end
|
106
|
-
|
107
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Delayed::MessageSending do
|
4
|
-
describe "handle_asynchronously" do
|
5
|
-
class Story
|
6
|
-
def tell!(arg)
|
7
|
-
end
|
8
|
-
handle_asynchronously :tell!
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should alias original method" do
|
12
|
-
Story.new.should respond_to(:tell_without_delay!)
|
13
|
-
Story.new.should respond_to(:tell_with_delay!)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should create a PerformableMethod" do
|
17
|
-
story = Story.new
|
18
|
-
lambda {
|
19
|
-
job = story.tell!(1)
|
20
|
-
job.payload_object.class.should == Delayed::PerformableMethod
|
21
|
-
job.payload_object.method_name.should == :tell_without_delay!
|
22
|
-
job.payload_object.args.should == [1]
|
23
|
-
}.should change { Delayed::Job.count }
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'with options' do
|
27
|
-
class Fable
|
28
|
-
class << self
|
29
|
-
attr_accessor :importance
|
30
|
-
end
|
31
|
-
def tell
|
32
|
-
end
|
33
|
-
handle_asynchronously :tell, :priority => Proc.new { self.importance }
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should set the priority based on the Fable importance' do
|
37
|
-
Fable.importance = 10
|
38
|
-
job = Fable.new.tell
|
39
|
-
job.priority.should == 10
|
40
|
-
|
41
|
-
Fable.importance = 20
|
42
|
-
job = Fable.new.tell
|
43
|
-
job.priority.should == 20
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'using a proc with parament' do
|
47
|
-
class Yarn
|
48
|
-
attr_accessor :importance
|
49
|
-
def spin
|
50
|
-
end
|
51
|
-
handle_asynchronously :spin, :priority => Proc.new {|y| y.importance }
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should set the priority based on the Fable importance' do
|
55
|
-
job = Yarn.new.tap {|y| y.importance = 10 }.spin
|
56
|
-
job.priority.should == 10
|
57
|
-
|
58
|
-
job = Yarn.new.tap {|y| y.importance = 20 }.spin
|
59
|
-
job.priority.should == 20
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "delay" do
|
66
|
-
it "should create a new PerformableMethod job" do
|
67
|
-
lambda {
|
68
|
-
job = "hello".delay.count('l')
|
69
|
-
job.payload_object.class.should == Delayed::PerformableMethod
|
70
|
-
job.payload_object.method_name.should == :count
|
71
|
-
job.payload_object.args.should == ['l']
|
72
|
-
}.should change { Delayed::Job.count }.by(1)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should set default priority" do
|
76
|
-
Delayed::Worker.default_priority = 99
|
77
|
-
job = Object.delay.to_s
|
78
|
-
job.priority.should == 99
|
79
|
-
Delayed::Worker.default_priority = 0
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should set job options" do
|
83
|
-
run_at = Time.parse('2010-05-03 12:55 AM')
|
84
|
-
job = Object.delay(:priority => 20, :run_at => run_at).to_s
|
85
|
-
job.run_at.should == run_at
|
86
|
-
job.priority.should == 20
|
87
|
-
end
|
88
|
-
|
89
|
-
class FairyTail
|
90
|
-
attr_accessor :happy_ending
|
91
|
-
def tell
|
92
|
-
@happy_ending = true
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should not delay the job when delay_jobs is false" do
|
97
|
-
Delayed::Worker.delay_jobs = false
|
98
|
-
fairy_tail = FairyTail.new
|
99
|
-
lambda {
|
100
|
-
lambda {
|
101
|
-
fairy_tail.delay.tell
|
102
|
-
}.should change(fairy_tail, :happy_ending).from(nil).to(true)
|
103
|
-
}.should_not change { Delayed::Job.count }
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should delay the job when delay_jobs is true" do
|
107
|
-
Delayed::Worker.delay_jobs = true
|
108
|
-
fairy_tail = FairyTail.new
|
109
|
-
lambda {
|
110
|
-
lambda {
|
111
|
-
fairy_tail.delay.tell
|
112
|
-
}.should_not change(fairy_tail, :happy_ending)
|
113
|
-
}.should change { Delayed::Job.count }.by(1)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'action_mailer'
|
4
|
-
class MyMailer < ActionMailer::Base
|
5
|
-
def signup(email)
|
6
|
-
mail :to => email, :subject => "Delaying Emails"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
describe ActionMailer::Base do
|
11
|
-
describe "delay" do
|
12
|
-
it "should enqueue a PerformableEmail job" do
|
13
|
-
lambda {
|
14
|
-
job = MyMailer.delay.signup('john@example.com')
|
15
|
-
job.payload_object.class.should == Delayed::PerformableMailer
|
16
|
-
job.payload_object.method_name.should == :signup
|
17
|
-
job.payload_object.args.should == ['john@example.com']
|
18
|
-
}.should change { Delayed::Job.count }.by(1)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "delay on a mail object" do
|
23
|
-
it "should raise an exception" do
|
24
|
-
lambda {
|
25
|
-
MyMailer.signup('john@example.com').delay
|
26
|
-
}.should raise_error(RuntimeError)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe Delayed::PerformableMailer do
|
31
|
-
describe "perform" do
|
32
|
-
before do
|
33
|
-
@email = mock('email', :deliver => true)
|
34
|
-
@mailer_class = mock('MailerClass', :signup => @email)
|
35
|
-
@mailer = Delayed::PerformableMailer.new(@mailer_class, :signup, ['john@example.com'])
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should call the method and #deliver on the mailer" do
|
39
|
-
@mailer_class.should_receive(:signup).with('john@example.com')
|
40
|
-
@email.should_receive(:deliver)
|
41
|
-
@mailer.perform
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Delayed::PerformableMethod do
|
4
|
-
describe "perform" do
|
5
|
-
before do
|
6
|
-
@method = Delayed::PerformableMethod.new("foo", :count, ['o'])
|
7
|
-
end
|
8
|
-
|
9
|
-
context "with the persisted record cannot be found" do
|
10
|
-
before do
|
11
|
-
@method.object = nil
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should be a no-op if object is nil" do
|
15
|
-
lambda { @method.perform }.should_not raise_error
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should call the method on the object" do
|
20
|
-
@method.object.should_receive(:count).with('o')
|
21
|
-
@method.perform
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should raise a NoMethodError if target method doesn't exist" do
|
26
|
-
lambda {
|
27
|
-
Delayed::PerformableMethod.new(Object, :method_that_does_not_exist, [])
|
28
|
-
}.should raise_error(NoMethodError)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should not raise NoMethodError if target method is private" do
|
32
|
-
clazz = Class.new do
|
33
|
-
def private_method
|
34
|
-
end
|
35
|
-
private :private_method
|
36
|
-
end
|
37
|
-
lambda {
|
38
|
-
Delayed::PerformableMethod.new(clazz.new, :private_method, [])
|
39
|
-
}.should_not raise_error(NoMethodError)
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "hooks" do
|
43
|
-
%w(enqueue before after success).each do |hook|
|
44
|
-
it "should delegate #{hook} hook to object" do
|
45
|
-
story = Story.new
|
46
|
-
story.should_receive(hook).with(an_instance_of(Delayed::Job))
|
47
|
-
story.delay.tell.invoke_job
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
%w(before after success).each do |hook|
|
52
|
-
it "should delegate #{hook} hook to object when delay_jobs = false" do
|
53
|
-
Delayed::Worker.delay_jobs = false
|
54
|
-
story = Story.new
|
55
|
-
story.should_receive(hook).with(an_instance_of(Delayed::Job))
|
56
|
-
story.delay.tell
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should delegate error hook to object" do
|
61
|
-
story = Story.new
|
62
|
-
story.should_receive(:error).with(an_instance_of(Delayed::Job), an_instance_of(RuntimeError))
|
63
|
-
story.should_receive(:tell).and_raise(RuntimeError)
|
64
|
-
lambda { story.delay.tell.invoke_job }.should raise_error
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should delegate error hook to object when delay_jobs = false" do
|
68
|
-
Delayed::Worker.delay_jobs = false
|
69
|
-
story = Story.new
|
70
|
-
story.should_receive(:error).with(an_instance_of(Delayed::Job), an_instance_of(RuntimeError))
|
71
|
-
story.should_receive(:tell).and_raise(RuntimeError)
|
72
|
-
lambda { story.delay.tell }.should raise_error
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should delegate failure hook to object" do
|
76
|
-
method = Delayed::PerformableMethod.new("object", :size, [])
|
77
|
-
method.object.should_receive(:failure)
|
78
|
-
method.failure
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should delegate failure hook to object when delay_jobs = false" do
|
82
|
-
Delayed::Worker.delay_jobs = false
|
83
|
-
method = Delayed::PerformableMethod.new("object", :size, [])
|
84
|
-
method.object.should_receive(:failure)
|
85
|
-
method.failure
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
end
|
data/spec/sample_jobs.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
class NamedJob < Struct.new(:perform)
|
2
|
-
def display_name
|
3
|
-
'named_job'
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
class SimpleJob
|
8
|
-
cattr_accessor :runs; self.runs = 0
|
9
|
-
def perform; @@runs += 1; end
|
10
|
-
end
|
11
|
-
|
12
|
-
class ErrorJob
|
13
|
-
cattr_accessor :runs; self.runs = 0
|
14
|
-
def perform; raise 'did not work'; end
|
15
|
-
end
|
16
|
-
|
17
|
-
class CustomRescheduleJob < Struct.new(:offset)
|
18
|
-
cattr_accessor :runs; self.runs = 0
|
19
|
-
def perform; raise 'did not work'; end
|
20
|
-
def reschedule_at(time, attempts); time + offset; end
|
21
|
-
end
|
22
|
-
|
23
|
-
class LongRunningJob
|
24
|
-
def perform; sleep 250; end
|
25
|
-
end
|
26
|
-
|
27
|
-
class OnPermanentFailureJob < SimpleJob
|
28
|
-
def failure; end
|
29
|
-
def max_attempts; 1; end
|
30
|
-
end
|
31
|
-
|
32
|
-
module M
|
33
|
-
class ModuleJob
|
34
|
-
cattr_accessor :runs; self.runs = 0
|
35
|
-
def perform; @@runs += 1; end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class CallbackJob
|
40
|
-
cattr_accessor :messages
|
41
|
-
|
42
|
-
def enqueue(job)
|
43
|
-
self.class.messages << 'enqueue'
|
44
|
-
end
|
45
|
-
|
46
|
-
def before(job)
|
47
|
-
self.class.messages << 'before'
|
48
|
-
end
|
49
|
-
|
50
|
-
def perform
|
51
|
-
self.class.messages << 'perform'
|
52
|
-
end
|
53
|
-
|
54
|
-
def after(job)
|
55
|
-
self.class.messages << 'after'
|
56
|
-
end
|
57
|
-
|
58
|
-
def success(job)
|
59
|
-
self.class.messages << 'success'
|
60
|
-
end
|
61
|
-
|
62
|
-
def error(job, error)
|
63
|
-
self.class.messages << "error: #{error.class}"
|
64
|
-
end
|
65
|
-
|
66
|
-
def failure(job)
|
67
|
-
self.class.messages << 'failure'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class EnqueueJobMod < SimpleJob
|
72
|
-
def enqueue(job)
|
73
|
-
job.run_at = 20.minutes.from_now
|
74
|
-
end
|
75
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'logger'
|
5
|
-
|
6
|
-
require 'rails'
|
7
|
-
require 'action_mailer'
|
8
|
-
require 'active_support/dependencies'
|
9
|
-
require 'active_record'
|
10
|
-
|
11
|
-
require 'delayed_job'
|
12
|
-
require 'delayed/backend/shared_spec'
|
13
|
-
|
14
|
-
Delayed::Worker.logger = Logger.new('/tmp/dj.log')
|
15
|
-
ENV['RAILS_ENV'] = 'test'
|
16
|
-
|
17
|
-
Delayed::Worker.backend = :test
|
18
|
-
|
19
|
-
# Add this directory so the ActiveSupport autoloading works
|
20
|
-
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
|
21
|
-
|
22
|
-
# Add this to simulate Railtie initializer being executed
|
23
|
-
ActionMailer::Base.send(:extend, Delayed::DelayMail)
|
24
|
-
|
25
|
-
|
26
|
-
# Used to test interactions between DJ and an ORM
|
27
|
-
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
28
|
-
ActiveRecord::Base.logger = Delayed::Worker.logger
|
29
|
-
ActiveRecord::Migration.verbose = false
|
30
|
-
|
31
|
-
ActiveRecord::Schema.define do
|
32
|
-
create_table :stories, :primary_key => :story_id, :force => true do |table|
|
33
|
-
table.string :text
|
34
|
-
table.boolean :scoped, :default => true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class Story < ActiveRecord::Base
|
39
|
-
set_primary_key :story_id
|
40
|
-
def tell; text; end
|
41
|
-
def whatever(n, _); tell*n; end
|
42
|
-
default_scope where(:scoped => true)
|
43
|
-
|
44
|
-
handle_asynchronously :whatever
|
45
|
-
end
|