taskinator 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/taskinator/definition/builder.rb +6 -4
- data/lib/taskinator/job_worker.rb +1 -0
- data/lib/taskinator/persistence.rb +4 -2
- data/lib/taskinator/process_worker.rb +1 -0
- data/lib/taskinator/queues.rb +31 -1
- data/lib/taskinator/task.rb +10 -0
- data/lib/taskinator/task_worker.rb +1 -0
- data/lib/taskinator/version.rb +1 -1
- data/spec/examples/queue_adapter_examples.rb +26 -11
- data/spec/spec_helper.rb +4 -0
- data/spec/support/test_queue.rb +38 -0
- data/spec/taskinator/job_worker_spec.rb +3 -1
- data/spec/taskinator/process_spec.rb +5 -0
- data/spec/taskinator/process_worker_spec.rb +3 -1
- data/spec/taskinator/queues/sidekiq_spec.rb +3 -1
- data/spec/taskinator/task_spec.rb +13 -0
- data/spec/taskinator/task_worker_spec.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96866a7042bc2b7082aaeead94c5c90f00448f0b
|
4
|
+
data.tar.gz: 42636386ce754b64ce167fe858a59e8c2a0a8286
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 061588463242d2d1d11827a339dc17a7903b07631b7194a7ce43639e1d3c4c1a96ec7a24cd62a79e7bb8fa0354a59539ae7fc026377acc22be801f816b6bd3e0
|
7
|
+
data.tar.gz: 19da642b98496489815a1f2e741cda7e8f6fc9885c2becf896e09be7f48b7cdf0d85a5c0c8fb9e9bcd2aac26ecfed2fdcb7bdbb4d114d52faff356ca56eddf73
|
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ GIT
|
|
8
8
|
PATH
|
9
9
|
remote: .
|
10
10
|
specs:
|
11
|
-
taskinator (0.0.
|
11
|
+
taskinator (0.0.5)
|
12
12
|
connection_pool (>= 2.0.0)
|
13
13
|
json (>= 1.8.1)
|
14
14
|
redis (>= 3.0.6)
|
@@ -82,9 +82,9 @@ GEM
|
|
82
82
|
rspec-core (~> 3.1.0)
|
83
83
|
rspec-expectations (~> 3.1.0)
|
84
84
|
rspec-mocks (~> 3.1.0)
|
85
|
-
rspec-core (3.1.
|
85
|
+
rspec-core (3.1.3)
|
86
86
|
rspec-support (~> 3.1.0)
|
87
|
-
rspec-expectations (3.1.
|
87
|
+
rspec-expectations (3.1.1)
|
88
88
|
diff-lcs (>= 1.2.0, < 2.0)
|
89
89
|
rspec-support (~> 3.1.0)
|
90
90
|
rspec-mocks (3.1.0)
|
@@ -31,16 +31,18 @@ module Taskinator
|
|
31
31
|
|
32
32
|
# dynamically defines tasks, using the given @iterator method
|
33
33
|
# the definition will be evaluated for each yielded item
|
34
|
-
def for_each(
|
35
|
-
raise ArgumentError, '
|
36
|
-
raise NoMethodError,
|
34
|
+
def for_each(method, options={}, &block)
|
35
|
+
raise ArgumentError, 'method' if method.nil?
|
36
|
+
raise NoMethodError, method unless @executor.respond_to?(method)
|
37
37
|
raise ArgumentError, 'block' unless block_given?
|
38
38
|
|
39
|
-
@executor.send(
|
39
|
+
@executor.send(method, *@args) do |*args|
|
40
40
|
Builder.new(@process, @definition, args).instance_eval(&block)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
alias_method :transform, :for_each
|
45
|
+
|
44
46
|
# defines a task which executes the given @method
|
45
47
|
def task(method, options={})
|
46
48
|
raise ArgumentError, 'method' if method.nil?
|
@@ -282,13 +282,15 @@ module Taskinator
|
|
282
282
|
if values.is_a?(Array)
|
283
283
|
|
284
284
|
values = values.collect {|value|
|
285
|
-
|
285
|
+
# is it a global id?
|
286
|
+
value.respond_to?(:model_id) && value.respond_to?(:find) ? value.find : value
|
286
287
|
}
|
287
288
|
|
288
289
|
elsif values.is_a?(Hash)
|
289
290
|
|
290
291
|
values.each {|key, value|
|
291
|
-
|
292
|
+
# is it a global id?
|
293
|
+
values[key] = value.find if value.respond_to?(:model_id) && value.respond_to?(:find)
|
292
294
|
}
|
293
295
|
|
294
296
|
end
|
data/lib/taskinator/queues.rb
CHANGED
@@ -3,12 +3,42 @@ module Taskinator
|
|
3
3
|
|
4
4
|
def self.create_adapter(adapter, config={})
|
5
5
|
begin
|
6
|
-
send("create_#{adapter}_adapter", config)
|
6
|
+
LoggedAdapter.new(send("create_#{adapter}_adapter", config))
|
7
7
|
rescue NoMethodError
|
8
8
|
raise "The queue adapter `#{adapter}` is not yet supported or it's runtime isn't loaded."
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
class LoggedAdapter < Delegator
|
13
|
+
|
14
|
+
attr_reader :adapter
|
15
|
+
|
16
|
+
def initialize(adapter)
|
17
|
+
Taskinator.logger.info("Initialized '#{adapter.class.name}' queue adapter")
|
18
|
+
@adapter = adapter
|
19
|
+
end
|
20
|
+
|
21
|
+
def __getobj__
|
22
|
+
adapter
|
23
|
+
end
|
24
|
+
|
25
|
+
def enqueue_process(process)
|
26
|
+
Taskinator.logger.info("Enqueuing process #{process}")
|
27
|
+
adapter.enqueue_process(process)
|
28
|
+
end
|
29
|
+
|
30
|
+
def enqueue_task(task)
|
31
|
+
Taskinator.logger.info("Enqueuing task #{task}")
|
32
|
+
adapter.enqueue_task(task)
|
33
|
+
end
|
34
|
+
|
35
|
+
def enqueue_job(job)
|
36
|
+
Taskinator.logger.info("Enqueuing job #{job}")
|
37
|
+
adapter.enqueue_job(job)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
12
42
|
end
|
13
43
|
end
|
14
44
|
|
data/lib/taskinator/task.rb
CHANGED
@@ -170,8 +170,18 @@ module Taskinator
|
|
170
170
|
@args = args
|
171
171
|
end
|
172
172
|
|
173
|
+
def enqueue
|
174
|
+
Taskinator.queue.enqueue_job(self)
|
175
|
+
end
|
176
|
+
|
173
177
|
def perform(&block)
|
174
178
|
yield(job, args)
|
179
|
+
@is_complete = true
|
180
|
+
end
|
181
|
+
|
182
|
+
# NOTE: this _does not_ work when checking out-of-process
|
183
|
+
def can_complete_task?
|
184
|
+
defined?(@is_complete) && @is_complete
|
175
185
|
end
|
176
186
|
|
177
187
|
def accept(visitor)
|
data/lib/taskinator/version.rb
CHANGED
@@ -3,26 +3,41 @@ require 'spec_helper'
|
|
3
3
|
shared_examples_for "a queue adapter" do |adapter_name, adapter_type|
|
4
4
|
|
5
5
|
subject { adapter_type.new({}) }
|
6
|
+
let(:job) { double('job') }
|
6
7
|
|
7
8
|
it "should instantiate adapter" do
|
8
9
|
Taskinator.queue_adapter = adapter_name
|
9
|
-
expect(Taskinator.queue).to be_a(adapter_type)
|
10
|
+
expect(Taskinator.queue.adapter).to be_a(adapter_type)
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
describe "#enqueue_process" do
|
14
|
+
it { expect(subject).to respond_to(:enqueue_process) }
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
it "should enqueue a process" do
|
17
|
+
expect {
|
18
|
+
subject.enqueue_process(double('process', :uuid => 'xx-xx-xx-xx'))
|
19
|
+
}.to_not raise_error
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
|
-
|
23
|
+
describe "#enqueue_task" do
|
24
|
+
it { expect(subject).to respond_to(:enqueue_task) }
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
it "should enqueue a task" do
|
27
|
+
expect {
|
28
|
+
subject.enqueue_task(double('task', :uuid => 'xx-xx-xx-xx'))
|
29
|
+
}.to_not raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#enqueue_job" do
|
34
|
+
it { expect(subject).to respond_to(:enqueue_job) }
|
35
|
+
|
36
|
+
it "should enqueue a job" do
|
37
|
+
expect {
|
38
|
+
subject.enqueue_job(double('job', :uuid => 'xx-xx-xx-xx', :job => job))
|
39
|
+
}.to_not raise_error
|
40
|
+
end
|
26
41
|
end
|
27
42
|
|
28
43
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -42,6 +42,10 @@ RSpec.configure do |config|
|
|
42
42
|
config.order = :random
|
43
43
|
config.fail_fast = (ENV["FAIL_FAST"] == 1)
|
44
44
|
|
45
|
+
config.before(:each) do
|
46
|
+
Taskinator.queue_adapter = :test_queue
|
47
|
+
end
|
48
|
+
|
45
49
|
config.before(:each, :redis => true) do
|
46
50
|
Taskinator.redis = { :namespace => 'taskinator:test' }
|
47
51
|
Taskinator.redis do |conn|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Taskinator
|
2
|
+
module Queues
|
3
|
+
|
4
|
+
def self.create_test_queue_adapter(config={})
|
5
|
+
TestQueueAdapter::new()
|
6
|
+
end
|
7
|
+
|
8
|
+
class TestQueueAdapter
|
9
|
+
|
10
|
+
attr_reader :processes
|
11
|
+
attr_reader :tasks
|
12
|
+
attr_reader :jobs
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
clear
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear
|
19
|
+
@processes = []
|
20
|
+
@tasks = []
|
21
|
+
@jobs = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def enqueue_process(process)
|
25
|
+
@processes << process
|
26
|
+
end
|
27
|
+
|
28
|
+
def enqueue_task(task)
|
29
|
+
@tasks << task
|
30
|
+
end
|
31
|
+
|
32
|
+
def enqueue_job(job)
|
33
|
+
@jobs << job
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -65,7 +65,9 @@ describe Taskinator::JobWorker do
|
|
65
65
|
allow(Taskinator::Task).to receive(:fetch).with(uuid) { job }
|
66
66
|
allow(job).to receive(:start!) { raise NotImplementedError }
|
67
67
|
expect(job).to receive(:fail!).with(NotImplementedError)
|
68
|
-
|
68
|
+
expect {
|
69
|
+
subject.perform
|
70
|
+
}.to raise_error(NotImplementedError)
|
69
71
|
end
|
70
72
|
|
71
73
|
end
|
@@ -43,7 +43,9 @@ describe Taskinator::ProcessWorker do
|
|
43
43
|
allow(Taskinator::Process).to receive(:fetch).with(uuid) { process }
|
44
44
|
allow(process).to receive(:start!) { raise NotImplementedError }
|
45
45
|
expect(process).to receive(:fail!).with(NotImplementedError)
|
46
|
-
|
46
|
+
expect {
|
47
|
+
subject.perform
|
48
|
+
}.to raise_error(NotImplementedError)
|
47
49
|
end
|
48
50
|
|
49
51
|
end
|
@@ -2,7 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Taskinator::Queues::SidekiqAdapter do
|
4
4
|
|
5
|
-
it_should_behave_like "a queue adapter", :sidekiq, Taskinator::Queues::SidekiqAdapter
|
5
|
+
it_should_behave_like "a queue adapter", :sidekiq, Taskinator::Queues::SidekiqAdapter do
|
6
|
+
let(:job) { double('job', :get_sidekiq_options => {}) }
|
7
|
+
end
|
6
8
|
|
7
9
|
let(:adapter) { Taskinator::Queues::SidekiqAdapter }
|
8
10
|
let(:uuid) { SecureRandom.uuid }
|
@@ -61,6 +61,11 @@ describe Taskinator::Task do
|
|
61
61
|
subject.enqueue!
|
62
62
|
expect(subject.current_state.name).to eq(:enqueued)
|
63
63
|
}
|
64
|
+
it {
|
65
|
+
expect {
|
66
|
+
subject.enqueue!
|
67
|
+
}.to change { Taskinator.queue.tasks.length }.by(1)
|
68
|
+
}
|
64
69
|
end
|
65
70
|
|
66
71
|
describe "#start!" do
|
@@ -216,6 +221,14 @@ describe Taskinator::Task do
|
|
216
221
|
let(:process) { Class.new(Taskinator::Process).new(definition) }
|
217
222
|
subject { Taskinator::Task.define_job_task(process, TestJob, {:a => 1, :b => 2}) }
|
218
223
|
|
224
|
+
describe "#enqueue!" do
|
225
|
+
it {
|
226
|
+
expect {
|
227
|
+
subject.enqueue!
|
228
|
+
}.to change { Taskinator.queue.jobs.length }.by(1)
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
219
232
|
describe "#perform" do
|
220
233
|
it {
|
221
234
|
block = SpecSupport::Block.new()
|
@@ -59,7 +59,9 @@ describe Taskinator::TaskWorker do
|
|
59
59
|
allow(Taskinator::Task).to receive(:fetch).with(uuid) { task }
|
60
60
|
allow(task).to receive(:start!) { raise NotImplementedError }
|
61
61
|
expect(task).to receive(:fail!).with(NotImplementedError)
|
62
|
-
|
62
|
+
expect {
|
63
|
+
subject.perform
|
64
|
+
}.to raise_error(NotImplementedError)
|
63
65
|
end
|
64
66
|
|
65
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taskinator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Stefano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -253,6 +253,7 @@ files:
|
|
253
253
|
- spec/support/delayed_job.rb
|
254
254
|
- spec/support/spec_support.rb
|
255
255
|
- spec/support/test_flow.rb
|
256
|
+
- spec/support/test_queue.rb
|
256
257
|
- spec/taskinator/api_spec.rb
|
257
258
|
- spec/taskinator/complex_process_spec.rb
|
258
259
|
- spec/taskinator/definition/builder_spec.rb
|
@@ -305,6 +306,7 @@ test_files:
|
|
305
306
|
- spec/support/delayed_job.rb
|
306
307
|
- spec/support/spec_support.rb
|
307
308
|
- spec/support/test_flow.rb
|
309
|
+
- spec/support/test_queue.rb
|
308
310
|
- spec/taskinator/api_spec.rb
|
309
311
|
- spec/taskinator/complex_process_spec.rb
|
310
312
|
- spec/taskinator/definition/builder_spec.rb
|