taskinator 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +77 -0
- data/Gemfile.lock +2 -1
- data/README.md +1 -1
- data/lib/taskinator/api.rb +3 -1
- data/lib/taskinator/create_process_worker.rb +60 -0
- data/lib/taskinator/definition.rb +47 -8
- data/lib/taskinator/job_worker.rb +2 -2
- data/lib/taskinator/logger.rb +13 -75
- data/lib/taskinator/persistence.rb +48 -40
- data/lib/taskinator/process.rb +13 -6
- data/lib/taskinator/process_worker.rb +3 -1
- data/lib/taskinator/queues/delayed_job.rb +12 -5
- data/lib/taskinator/queues/resque.rb +16 -5
- data/lib/taskinator/queues/sidekiq.rb +14 -5
- data/lib/taskinator/queues.rb +12 -0
- data/lib/taskinator/task.rb +21 -8
- data/lib/taskinator/task_worker.rb +3 -1
- data/lib/taskinator/tasks.rb +1 -1
- data/lib/taskinator/version.rb +1 -1
- data/lib/taskinator.rb +20 -1
- data/spec/examples/queue_adapter_examples.rb +10 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/mock_definition.rb +22 -0
- data/spec/support/spec_support.rb +3 -1
- data/spec/support/test_definition.rb +3 -0
- data/spec/support/test_process.rb +2 -0
- data/spec/support/test_queue.rb +7 -1
- data/spec/support/test_task.rb +2 -0
- data/spec/taskinator/api_spec.rb +2 -2
- data/spec/taskinator/create_process_worker_spec.rb +44 -0
- data/spec/taskinator/definition/builder_spec.rb +5 -5
- data/spec/taskinator/definition_spec.rb +103 -6
- data/spec/taskinator/executor_spec.rb +1 -1
- data/spec/taskinator/job_worker_spec.rb +3 -3
- data/spec/taskinator/persistence_spec.rb +12 -19
- data/spec/taskinator/process_spec.rb +29 -5
- data/spec/taskinator/process_worker_spec.rb +3 -3
- data/spec/taskinator/queues/delayed_job_spec.rb +23 -6
- data/spec/taskinator/queues/resque_spec.rb +27 -6
- data/spec/taskinator/queues/sidekiq_spec.rb +28 -10
- data/spec/taskinator/task_spec.rb +80 -7
- data/spec/taskinator/task_worker_spec.rb +3 -3
- data/spec/taskinator/{intermodal_spec.rb → taskinator_spec.rb} +35 -1
- data/spec/taskinator/tasks_spec.rb +1 -2
- data/taskinator.gemspec +17 -15
- metadata +30 -4
@@ -2,21 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Taskinator::Persistence, :redis => true do
|
4
4
|
|
5
|
-
module TestDefinition
|
6
|
-
extend Taskinator::Definition
|
7
|
-
end
|
8
|
-
|
9
5
|
let(:definition) { TestDefinition }
|
10
6
|
|
11
|
-
class TestProcess < Taskinator::Process
|
12
|
-
end
|
13
|
-
|
14
|
-
class TestTask < Taskinator::Task
|
15
|
-
end
|
16
|
-
|
17
7
|
describe "class methods" do
|
18
8
|
subject {
|
19
|
-
Class.new
|
9
|
+
Class.new do
|
20
10
|
include Taskinator::Persistence
|
21
11
|
end
|
22
12
|
}
|
@@ -99,7 +89,7 @@ describe Taskinator::Persistence, :redis => true do
|
|
99
89
|
|
100
90
|
describe "instance methods" do
|
101
91
|
subject {
|
102
|
-
klass = Class.new
|
92
|
+
klass = Class.new do
|
103
93
|
include Taskinator::Persistence
|
104
94
|
|
105
95
|
def self.base_key
|
@@ -112,7 +102,7 @@ describe Taskinator::Persistence, :redis => true do
|
|
112
102
|
@uuid = SecureRandom.uuid
|
113
103
|
end
|
114
104
|
end
|
115
|
-
klass.new
|
105
|
+
klass.new
|
116
106
|
}
|
117
107
|
|
118
108
|
describe "#key" do
|
@@ -122,7 +112,7 @@ describe Taskinator::Persistence, :redis => true do
|
|
122
112
|
end
|
123
113
|
|
124
114
|
describe "#save" do
|
125
|
-
pending
|
115
|
+
pending __FILE__
|
126
116
|
end
|
127
117
|
|
128
118
|
describe "#load_workflow_state" do
|
@@ -141,14 +131,16 @@ describe Taskinator::Persistence, :redis => true do
|
|
141
131
|
describe "#fail" do
|
142
132
|
it "persists error information" do
|
143
133
|
begin
|
144
|
-
raise
|
145
|
-
|
134
|
+
# raise this error in a block, so there is a backtrace!
|
135
|
+
raise StandardError.new('a error')
|
136
|
+
rescue => e
|
146
137
|
subject.fail(e)
|
147
138
|
end
|
148
139
|
|
149
140
|
Taskinator.redis do |conn|
|
150
141
|
expect(conn.hget(subject.key, :error_type)).to eq('StandardError')
|
151
142
|
expect(conn.hget(subject.key, :error_message)).to eq('a error')
|
143
|
+
expect(conn.hget(subject.key, :error_backtrace)).to_not be_empty
|
152
144
|
end
|
153
145
|
end
|
154
146
|
end
|
@@ -157,10 +149,11 @@ describe Taskinator::Persistence, :redis => true do
|
|
157
149
|
it "retrieves error information" do
|
158
150
|
error = nil
|
159
151
|
begin
|
160
|
-
raise
|
161
|
-
|
152
|
+
# raise this error in a block, so there is a backtrace!
|
153
|
+
raise StandardError.new('a error')
|
154
|
+
rescue => e
|
162
155
|
error = e
|
163
|
-
subject.fail(
|
156
|
+
subject.fail(error)
|
164
157
|
end
|
165
158
|
|
166
159
|
expect(subject.error).to eq([error.class.name, error.message, error.backtrace])
|
@@ -2,11 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Taskinator::Process do
|
4
4
|
|
5
|
-
let(:definition)
|
6
|
-
Module.new() do
|
7
|
-
extend Taskinator::Definition
|
8
|
-
end
|
9
|
-
end
|
5
|
+
let(:definition) { TestDefinition }
|
10
6
|
|
11
7
|
describe "Base" do
|
12
8
|
|
@@ -39,6 +35,17 @@ describe Taskinator::Process do
|
|
39
35
|
it { expect(subject.to_s).to match(/#{subject.uuid}/) }
|
40
36
|
end
|
41
37
|
|
38
|
+
describe "#queue" do
|
39
|
+
it {
|
40
|
+
expect(subject.queue).to be_nil
|
41
|
+
}
|
42
|
+
|
43
|
+
it {
|
44
|
+
process = Class.new(Taskinator::Process).new(definition, :queue => :foo)
|
45
|
+
expect(process.queue).to eq(:foo)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
42
49
|
describe "#current_state" do
|
43
50
|
it { expect(subject).to be_a(::Workflow) }
|
44
51
|
it { expect(subject.current_state).to_not be_nil }
|
@@ -189,10 +196,15 @@ describe Taskinator::Process do
|
|
189
196
|
expect(visitor).to receive(:visit_args).with(:options)
|
190
197
|
expect(visitor).to receive(:visit_task_reference).with(:parent)
|
191
198
|
expect(visitor).to receive(:visit_tasks)
|
199
|
+
expect(visitor).to receive(:visit_attribute).with(:queue)
|
192
200
|
|
193
201
|
subject.accept(visitor)
|
194
202
|
}
|
195
203
|
end
|
204
|
+
|
205
|
+
describe "#reload" do
|
206
|
+
it { expect(subject.reload).to_not be }
|
207
|
+
end
|
196
208
|
end
|
197
209
|
|
198
210
|
describe Taskinator::Process::Sequential do
|
@@ -222,6 +234,11 @@ describe Taskinator::Process do
|
|
222
234
|
Taskinator::Process.define_sequential_process_for(Object)
|
223
235
|
}.to raise_error(ArgumentError)
|
224
236
|
end
|
237
|
+
|
238
|
+
it "sets the queue to use" do
|
239
|
+
process = Taskinator::Process.define_sequential_process_for(definition, :queue => :foo)
|
240
|
+
expect(process.queue).to eq(:foo)
|
241
|
+
end
|
225
242
|
end
|
226
243
|
|
227
244
|
describe "#start!" do
|
@@ -296,6 +313,7 @@ describe Taskinator::Process do
|
|
296
313
|
expect(visitor).to receive(:visit_args).with(:options)
|
297
314
|
expect(visitor).to receive(:visit_task_reference).with(:parent)
|
298
315
|
expect(visitor).to receive(:visit_tasks)
|
316
|
+
expect(visitor).to receive(:visit_attribute).with(:queue)
|
299
317
|
|
300
318
|
subject.accept(visitor)
|
301
319
|
}
|
@@ -330,6 +348,11 @@ describe Taskinator::Process do
|
|
330
348
|
Taskinator::Process.define_concurrent_process_for(Object)
|
331
349
|
}.to raise_error(ArgumentError)
|
332
350
|
end
|
351
|
+
|
352
|
+
it "sets the queue to use" do
|
353
|
+
process = Taskinator::Process.define_concurrent_process_for(definition, Taskinator::CompleteOn::First, :queue => :foo)
|
354
|
+
expect(process.queue).to eq(:foo)
|
355
|
+
end
|
333
356
|
end
|
334
357
|
|
335
358
|
describe "#start!" do
|
@@ -435,6 +458,7 @@ describe Taskinator::Process do
|
|
435
458
|
expect(visitor).to receive(:visit_args).with(:options)
|
436
459
|
expect(visitor).to receive(:visit_task_reference).with(:parent)
|
437
460
|
expect(visitor).to receive(:visit_tasks)
|
461
|
+
expect(visitor).to receive(:visit_attribute).with(:queue)
|
438
462
|
|
439
463
|
subject.accept(visitor)
|
440
464
|
}
|
@@ -41,11 +41,11 @@ describe Taskinator::ProcessWorker do
|
|
41
41
|
it "should fail if process raises an error" do
|
42
42
|
process = mock_process
|
43
43
|
allow(Taskinator::Process).to receive(:fetch).with(uuid) { process }
|
44
|
-
allow(process).to receive(:start!) { raise
|
45
|
-
expect(process).to receive(:fail!).with(
|
44
|
+
allow(process).to receive(:start!) { raise StandardError }
|
45
|
+
expect(process).to receive(:fail!).with(StandardError)
|
46
46
|
expect {
|
47
47
|
subject.perform
|
48
|
-
}.to raise_error(
|
48
|
+
}.to raise_error(StandardError)
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
@@ -7,7 +7,28 @@ describe Taskinator::Queues::DelayedJobAdapter, :delayed_job do
|
|
7
7
|
let(:adapter) { Taskinator::Queues::DelayedJobAdapter }
|
8
8
|
let(:uuid) { SecureRandom.uuid }
|
9
9
|
|
10
|
-
subject { adapter.new
|
10
|
+
subject { adapter.new }
|
11
|
+
|
12
|
+
describe "CreateProcessWorker" do
|
13
|
+
let(:args) { Taskinator::Persistence.serialize(:foo => :bar) }
|
14
|
+
|
15
|
+
it "enqueues" do
|
16
|
+
expect {
|
17
|
+
subject.enqueue_create_process(MockDefinition.create, uuid, :foo => :bar)
|
18
|
+
}.to change(Delayed::Job.queue, :size).by(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "enqueues to specified queue" do
|
22
|
+
definition = MockDefinition.create(:other)
|
23
|
+
subject.enqueue_create_process(definition, uuid, :foo => :bar)
|
24
|
+
expect(Delayed::Job.contains?(adapter::CreateProcessWorker, [definition.name, uuid, args], :other)).to be
|
25
|
+
end
|
26
|
+
|
27
|
+
it "calls worker" do
|
28
|
+
expect_any_instance_of(Taskinator::CreateProcessWorker).to receive(:perform)
|
29
|
+
adapter::CreateProcessWorker.new(MockDefinition.create.name, uuid, args).perform
|
30
|
+
end
|
31
|
+
end
|
11
32
|
|
12
33
|
describe "ProcessWorker" do
|
13
34
|
it "enqueues processes" do
|
@@ -68,11 +89,7 @@ describe Taskinator::Queues::DelayedJobAdapter, :delayed_job do
|
|
68
89
|
adapter::JobWorker.new(uuid).perform
|
69
90
|
end
|
70
91
|
|
71
|
-
let(:definition)
|
72
|
-
Module.new() do
|
73
|
-
extend Taskinator::Definition
|
74
|
-
end
|
75
|
-
end
|
92
|
+
let(:definition) { TestDefinition }
|
76
93
|
|
77
94
|
it "performs invocation on job" do
|
78
95
|
args = {:a => 1}
|
@@ -7,7 +7,32 @@ describe Taskinator::Queues::ResqueAdapter, :resque do
|
|
7
7
|
let(:adapter) { Taskinator::Queues::ResqueAdapter }
|
8
8
|
let(:uuid) { SecureRandom.uuid }
|
9
9
|
|
10
|
-
subject { adapter.new
|
10
|
+
subject { adapter.new }
|
11
|
+
|
12
|
+
describe "CreateProcessWorker" do
|
13
|
+
let(:args) { Taskinator::Persistence.serialize(:foo => :bar) }
|
14
|
+
|
15
|
+
it "enqueues" do
|
16
|
+
worker = adapter::CreateProcessWorker
|
17
|
+
definition = MockDefinition.create
|
18
|
+
subject.enqueue_create_process(definition, uuid, :foo => :bar)
|
19
|
+
|
20
|
+
expect(worker).to have_queued(definition.name, uuid, args)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "enqueues to specified queue" do
|
24
|
+
worker = adapter::CreateProcessWorker
|
25
|
+
definition = MockDefinition.create(:other)
|
26
|
+
subject.enqueue_create_process(definition, uuid, :foo => :bar)
|
27
|
+
|
28
|
+
expect(worker).to have_queued(definition.name, uuid, args).in(:other)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "calls worker" do
|
32
|
+
expect_any_instance_of(Taskinator::CreateProcessWorker).to receive(:perform)
|
33
|
+
adapter::CreateProcessWorker.perform(MockDefinition.create.name, uuid, args)
|
34
|
+
end
|
35
|
+
end
|
11
36
|
|
12
37
|
describe "ProcessWorker" do
|
13
38
|
it "enqueues processes" do
|
@@ -87,11 +112,7 @@ describe Taskinator::Queues::ResqueAdapter, :resque do
|
|
87
112
|
adapter::JobWorker.perform(uuid)
|
88
113
|
end
|
89
114
|
|
90
|
-
let(:definition)
|
91
|
-
Module.new() do
|
92
|
-
extend Taskinator::Definition
|
93
|
-
end
|
94
|
-
end
|
115
|
+
let(:definition) { TestDefinition }
|
95
116
|
|
96
117
|
it "performs invocation on job" do
|
97
118
|
args = {:a => 1}
|
@@ -9,7 +9,29 @@ describe Taskinator::Queues::SidekiqAdapter, :sidekiq do
|
|
9
9
|
let(:adapter) { Taskinator::Queues::SidekiqAdapter }
|
10
10
|
let(:uuid) { SecureRandom.uuid }
|
11
11
|
|
12
|
-
subject { adapter.new
|
12
|
+
subject { adapter.new }
|
13
|
+
|
14
|
+
describe "CreateProcessWorker" do
|
15
|
+
let(:args) { Taskinator::Persistence.serialize(:foo => :bar) }
|
16
|
+
|
17
|
+
it "enqueues" do
|
18
|
+
worker = adapter::CreateProcessWorker
|
19
|
+
definition = MockDefinition.create
|
20
|
+
subject.enqueue_create_process(definition, uuid, :foo => :bar)
|
21
|
+
expect(worker).to have_enqueued_job(definition.name, uuid, args)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "enqueues to specified queue" do
|
25
|
+
subject.enqueue_create_process(MockDefinition.create(:other), uuid, :foo => :bar)
|
26
|
+
expect(adapter::CreateProcessWorker).to be_processed_in_x(:other)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "calls worker" do
|
30
|
+
definition = MockDefinition.create
|
31
|
+
expect_any_instance_of(Taskinator::CreateProcessWorker).to receive(:perform)
|
32
|
+
adapter::CreateProcessWorker.new.perform(definition.name, uuid, args)
|
33
|
+
end
|
34
|
+
end
|
13
35
|
|
14
36
|
describe "ProcessWorker" do
|
15
37
|
it "enqueues processes" do
|
@@ -26,7 +48,7 @@ describe Taskinator::Queues::SidekiqAdapter, :sidekiq do
|
|
26
48
|
|
27
49
|
it "calls process worker" do
|
28
50
|
expect_any_instance_of(Taskinator::ProcessWorker).to receive(:perform)
|
29
|
-
adapter::ProcessWorker.new
|
51
|
+
adapter::ProcessWorker.new.perform(uuid)
|
30
52
|
end
|
31
53
|
end
|
32
54
|
|
@@ -45,7 +67,7 @@ describe Taskinator::Queues::SidekiqAdapter, :sidekiq do
|
|
45
67
|
|
46
68
|
it "calls task worker" do
|
47
69
|
expect_any_instance_of(Taskinator::TaskWorker).to receive(:perform)
|
48
|
-
adapter::TaskWorker.new
|
70
|
+
adapter::TaskWorker.new.perform(uuid)
|
49
71
|
end
|
50
72
|
end
|
51
73
|
|
@@ -78,14 +100,10 @@ describe Taskinator::Queues::SidekiqAdapter, :sidekiq do
|
|
78
100
|
|
79
101
|
it "calls job worker" do
|
80
102
|
expect_any_instance_of(Taskinator::JobWorker).to receive(:perform)
|
81
|
-
adapter::JobWorker.new
|
103
|
+
adapter::JobWorker.new.perform(uuid)
|
82
104
|
end
|
83
105
|
|
84
|
-
let(:definition)
|
85
|
-
Module.new() do
|
86
|
-
extend Taskinator::Definition
|
87
|
-
end
|
88
|
-
end
|
106
|
+
let(:definition) { TestDefinition }
|
89
107
|
|
90
108
|
it "performs invocation on job" do
|
91
109
|
args = {:a => 1}
|
@@ -100,7 +118,7 @@ describe Taskinator::Queues::SidekiqAdapter, :sidekiq do
|
|
100
118
|
|
101
119
|
allow(Taskinator::Task).to receive(:fetch).with(uuid) { job_task }
|
102
120
|
|
103
|
-
adapter::JobWorker.new
|
121
|
+
adapter::JobWorker.new.perform(uuid)
|
104
122
|
end
|
105
123
|
end
|
106
124
|
end
|
@@ -2,11 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Taskinator::Task do
|
4
4
|
|
5
|
-
let(:definition)
|
6
|
-
Module.new() do
|
7
|
-
extend Taskinator::Definition
|
8
|
-
end
|
9
|
-
end
|
5
|
+
let(:definition) { TestDefinition }
|
10
6
|
|
11
7
|
describe "Base" do
|
12
8
|
|
@@ -36,6 +32,17 @@ describe Taskinator::Task do
|
|
36
32
|
it { expect(subject.to_s).to match(/#{subject.uuid}/) }
|
37
33
|
end
|
38
34
|
|
35
|
+
describe "#queue" do
|
36
|
+
it {
|
37
|
+
expect(subject.queue).to be_nil
|
38
|
+
}
|
39
|
+
|
40
|
+
it {
|
41
|
+
task = Class.new(Taskinator::Task).new(process, :queue => :foo)
|
42
|
+
expect(task.queue).to eq(:foo)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
39
46
|
describe "#current_state" do
|
40
47
|
it { expect(subject).to be_a(::Workflow) }
|
41
48
|
it { expect(subject.current_state).to_not be_nil }
|
@@ -145,10 +152,15 @@ describe Taskinator::Task do
|
|
145
152
|
expect(visitor).to receive(:visit_process_reference).with(:process)
|
146
153
|
expect(visitor).to receive(:visit_task_reference).with(:next)
|
147
154
|
expect(visitor).to receive(:visit_args).with(:options)
|
155
|
+
expect(visitor).to receive(:visit_attribute).with(:queue)
|
148
156
|
|
149
157
|
subject.accept(visitor)
|
150
158
|
}
|
151
159
|
end
|
160
|
+
|
161
|
+
describe "#reload" do
|
162
|
+
it { expect(subject.reload).to_not be }
|
163
|
+
end
|
152
164
|
end
|
153
165
|
|
154
166
|
describe Taskinator::Task::Step do
|
@@ -160,6 +172,13 @@ describe Taskinator::Task do
|
|
160
172
|
let(:process) { Class.new(Taskinator::Process).new(definition) }
|
161
173
|
subject { Taskinator::Task.define_step_task(process, :method, {:a => 1, :b => 2}) }
|
162
174
|
|
175
|
+
describe ".define_step_task" do
|
176
|
+
it "sets the queue to use" do
|
177
|
+
task = Taskinator::Task.define_step_task(process, :method, {:a => 1, :b => 2}, :queue => :foo)
|
178
|
+
expect(task.queue).to eq(:foo)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
163
182
|
describe "#executor" do
|
164
183
|
it { expect(subject.executor).to_not be_nil }
|
165
184
|
it { expect(subject.executor).to be_a(definition) }
|
@@ -177,6 +196,18 @@ describe Taskinator::Task do
|
|
177
196
|
expect(subject).to receive(:fail!).with(error)
|
178
197
|
subject.start!
|
179
198
|
end
|
199
|
+
|
200
|
+
it "is instrumented" do
|
201
|
+
allow(subject.executor).to receive(subject.method)
|
202
|
+
|
203
|
+
instrumentation_block = SpecSupport::Block.new
|
204
|
+
expect(instrumentation_block).to receive(:call)
|
205
|
+
|
206
|
+
# temporary subscription
|
207
|
+
ActiveSupport::Notifications.subscribed(instrumentation_block, /execute_step_task/) do
|
208
|
+
subject.start!
|
209
|
+
end
|
210
|
+
end
|
180
211
|
end
|
181
212
|
|
182
213
|
describe "#can_complete_task?" do
|
@@ -203,6 +234,7 @@ describe Taskinator::Task do
|
|
203
234
|
expect(visitor).to receive(:visit_args).with(:options)
|
204
235
|
expect(visitor).to receive(:visit_attribute).with(:method)
|
205
236
|
expect(visitor).to receive(:visit_args).with(:args)
|
237
|
+
expect(visitor).to receive(:visit_attribute).with(:queue)
|
206
238
|
|
207
239
|
subject.accept(visitor)
|
208
240
|
}
|
@@ -224,6 +256,13 @@ describe Taskinator::Task do
|
|
224
256
|
let(:process) { Class.new(Taskinator::Process).new(definition) }
|
225
257
|
subject { Taskinator::Task.define_job_task(process, TestJob, {:a => 1, :b => 2}) }
|
226
258
|
|
259
|
+
describe ".define_job_task" do
|
260
|
+
it "sets the queue to use" do
|
261
|
+
task = Taskinator::Task.define_job_task(process, TestJob, {:a => 1, :b => 2}, :queue => :foo)
|
262
|
+
expect(task.queue).to eq(:foo)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
227
266
|
describe "#enqueue!" do
|
228
267
|
it {
|
229
268
|
expect {
|
@@ -234,11 +273,24 @@ describe Taskinator::Task do
|
|
234
273
|
|
235
274
|
describe "#perform" do
|
236
275
|
it {
|
237
|
-
block = SpecSupport::Block.new
|
276
|
+
block = SpecSupport::Block.new
|
238
277
|
expect(block).to receive(:call).with(TestJob, {:a => 1, :b => 2})
|
239
278
|
|
240
|
-
subject.perform
|
279
|
+
subject.perform(&block)
|
241
280
|
}
|
281
|
+
|
282
|
+
it "is instrumented" do
|
283
|
+
block = SpecSupport::Block.new
|
284
|
+
allow(block).to receive(:call)
|
285
|
+
|
286
|
+
instrumentation_block = SpecSupport::Block.new
|
287
|
+
expect(instrumentation_block).to receive(:call)
|
288
|
+
|
289
|
+
# temporary subscription
|
290
|
+
ActiveSupport::Notifications.subscribed(instrumentation_block, /execute_job_task/) do
|
291
|
+
subject.perform(&block)
|
292
|
+
end
|
293
|
+
end
|
242
294
|
end
|
243
295
|
|
244
296
|
describe "#accept" do
|
@@ -256,6 +308,7 @@ describe Taskinator::Task do
|
|
256
308
|
expect(visitor).to receive(:visit_args).with(:options)
|
257
309
|
expect(visitor).to receive(:visit_type).with(:job)
|
258
310
|
expect(visitor).to receive(:visit_args).with(:args)
|
311
|
+
expect(visitor).to receive(:visit_attribute).with(:queue)
|
259
312
|
|
260
313
|
subject.accept(visitor)
|
261
314
|
}
|
@@ -273,6 +326,13 @@ describe Taskinator::Task do
|
|
273
326
|
let(:sub_process) { Class.new(Taskinator::Process).new(definition) }
|
274
327
|
subject { Taskinator::Task.define_sub_process_task(process, sub_process) }
|
275
328
|
|
329
|
+
describe ".define_sub_process_task" do
|
330
|
+
it "sets the queue to use" do
|
331
|
+
task = Taskinator::Task.define_sub_process_task(process, sub_process, :queue => :foo)
|
332
|
+
expect(task.queue).to eq(:foo)
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
276
336
|
describe "#start!" do
|
277
337
|
it "delegates to sub process" do
|
278
338
|
expect(sub_process).to receive(:start)
|
@@ -285,6 +345,18 @@ describe Taskinator::Task do
|
|
285
345
|
expect(subject).to receive(:fail!).with(error)
|
286
346
|
subject.start!
|
287
347
|
end
|
348
|
+
|
349
|
+
it "is instrumented" do
|
350
|
+
allow(sub_process).to receive(:start)
|
351
|
+
|
352
|
+
instrumentation_block = SpecSupport::Block.new
|
353
|
+
expect(instrumentation_block).to receive(:call)
|
354
|
+
|
355
|
+
# temporary subscription
|
356
|
+
ActiveSupport::Notifications.subscribed(instrumentation_block, /execute_subprocess/) do
|
357
|
+
subject.start!
|
358
|
+
end
|
359
|
+
end
|
288
360
|
end
|
289
361
|
|
290
362
|
describe "#can_complete_task?" do
|
@@ -307,6 +379,7 @@ describe Taskinator::Task do
|
|
307
379
|
expect(visitor).to receive(:visit_task_reference).with(:next)
|
308
380
|
expect(visitor).to receive(:visit_args).with(:options)
|
309
381
|
expect(visitor).to receive(:visit_process).with(:sub_process)
|
382
|
+
expect(visitor).to receive(:visit_attribute).with(:queue)
|
310
383
|
|
311
384
|
subject.accept(visitor)
|
312
385
|
}
|
@@ -57,11 +57,11 @@ describe Taskinator::TaskWorker do
|
|
57
57
|
it "should fail if task raises an error" do
|
58
58
|
task = mock_task
|
59
59
|
allow(Taskinator::Task).to receive(:fetch).with(uuid) { task }
|
60
|
-
allow(task).to receive(:start!) { raise
|
61
|
-
expect(task).to receive(:fail!).with(
|
60
|
+
allow(task).to receive(:start!) { raise StandardError }
|
61
|
+
expect(task).to receive(:fail!).with(StandardError)
|
62
62
|
expect {
|
63
63
|
subject.perform
|
64
|
-
}.to raise_error(
|
64
|
+
}.to raise_error(StandardError)
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
@@ -48,10 +48,44 @@ describe Taskinator do
|
|
48
48
|
describe "#logger" do
|
49
49
|
it { expect(subject.logger).to_not be_nil }
|
50
50
|
it {
|
51
|
-
logger = Logger.new(
|
51
|
+
logger = Logger.new(File::NULL)
|
52
52
|
subject.logger = logger
|
53
53
|
expect(subject.logger).to eq(logger)
|
54
54
|
subject.logger = nil
|
55
55
|
}
|
56
56
|
end
|
57
|
+
|
58
|
+
describe "#instrumenter" do
|
59
|
+
it { expect(subject.instrumenter).to_not be_nil }
|
60
|
+
|
61
|
+
it {
|
62
|
+
orig_instrumenter = subject.instrumenter
|
63
|
+
|
64
|
+
instrumenter = Class.new().new
|
65
|
+
subject.instrumenter = instrumenter
|
66
|
+
expect(subject.instrumenter).to eq(instrumenter)
|
67
|
+
|
68
|
+
subject.instrumenter = orig_instrumenter
|
69
|
+
}
|
70
|
+
|
71
|
+
it "yields to given block" do
|
72
|
+
block = SpecSupport::Block.new
|
73
|
+
expect(block).to receive(:call)
|
74
|
+
|
75
|
+
subject.instrumenter.instrument(:foo, :bar => :baz, &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "instruments event, when activesupport is referenced" do
|
79
|
+
block = SpecSupport::Block.new
|
80
|
+
expect(block).to receive(:call)
|
81
|
+
|
82
|
+
# temporary subscription
|
83
|
+
ActiveSupport::Notifications.subscribed(block, /.*/) do
|
84
|
+
subject.instrumenter.instrument(:foo, :bar) do
|
85
|
+
:baz
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
57
91
|
end
|
@@ -17,13 +17,12 @@ describe Taskinator::Tasks do
|
|
17
17
|
|
18
18
|
describe "#initialize" do
|
19
19
|
it "starts with nil head" do
|
20
|
-
first = double()
|
21
20
|
instance = Taskinator::Tasks.new
|
22
21
|
expect(instance.head).to be_nil
|
23
22
|
end
|
24
23
|
|
25
24
|
it "assigns head to first element" do
|
26
|
-
first = double
|
25
|
+
first = double
|
27
26
|
instance = Taskinator::Tasks.new(first)
|
28
27
|
expect(instance.head).to eq(first)
|
29
28
|
end
|
data/taskinator.gemspec
CHANGED
@@ -21,27 +21,29 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = '>= 2.0.0'
|
22
22
|
|
23
23
|
# core
|
24
|
-
spec.add_dependency 'redis', '>= 3.2.1'
|
25
|
-
spec.add_dependency 'redis-namespace', '>= 1.5.2'
|
26
|
-
spec.add_dependency 'connection_pool', '>= 2.2.0'
|
27
|
-
spec.add_dependency 'json', '>= 1.8.2'
|
24
|
+
spec.add_dependency 'redis' , '>= 3.2.1'
|
25
|
+
spec.add_dependency 'redis-namespace' , '>= 1.5.2'
|
26
|
+
spec.add_dependency 'connection_pool' , '>= 2.2.0'
|
27
|
+
spec.add_dependency 'json' , '>= 1.8.2'
|
28
28
|
|
29
|
-
# spec.add_dependency 'workflow', '>= 1.3.0' # RubyGems not up to date as of 11 Nov 2014.
|
29
|
+
# spec.add_dependency 'workflow' , '>= 1.3.0' # RubyGems not up to date as of 11 Nov 2014.
|
30
30
|
|
31
31
|
# queues
|
32
|
-
spec.add_development_dependency 'sidekiq', '>= 3.0.0'
|
33
|
-
spec.add_development_dependency 'rspec-sidekiq', '>= 2.0.0'
|
32
|
+
spec.add_development_dependency 'sidekiq' , '>= 3.0.0'
|
33
|
+
spec.add_development_dependency 'rspec-sidekiq' , '>= 2.0.0'
|
34
34
|
|
35
|
-
spec.add_development_dependency 'delayed_job', '>= 4.0.0'
|
35
|
+
spec.add_development_dependency 'delayed_job' , '>= 4.0.0'
|
36
36
|
|
37
|
-
spec.add_development_dependency 'resque', '>= 1.25.2'
|
38
|
-
spec.add_development_dependency 'resque_spec', '>= 0.16.0'
|
37
|
+
spec.add_development_dependency 'resque' , '>= 1.25.2'
|
38
|
+
spec.add_development_dependency 'resque_spec' , '>= 0.16.0'
|
39
39
|
|
40
40
|
# other
|
41
|
-
spec.add_development_dependency 'bundler', '>= 1.6.0'
|
42
|
-
spec.add_development_dependency 'rake', '>= 10.3.0'
|
41
|
+
spec.add_development_dependency 'bundler' , '>= 1.6.0'
|
42
|
+
spec.add_development_dependency 'rake' , '>= 10.3.0'
|
43
|
+
spec.add_development_dependency 'activesupport' , '>= 4.0.0'
|
43
44
|
spec.add_development_dependency 'rspec'
|
44
|
-
spec.add_development_dependency 'coveralls', '>= 0.7.0'
|
45
|
-
spec.add_development_dependency 'pry', '>= 0.9.0'
|
46
|
-
spec.add_development_dependency 'pry-byebug', '>= 1.3.0'
|
45
|
+
spec.add_development_dependency 'coveralls' , '>= 0.7.0'
|
46
|
+
spec.add_development_dependency 'pry' , '>= 0.9.0'
|
47
|
+
spec.add_development_dependency 'pry-byebug' , '>= 1.3.0'
|
48
|
+
|
47
49
|
end
|