taskinator 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ae6a63807d0e3e2cb0c513f348eeab155abe830
4
- data.tar.gz: ce5a3c1168ff6a3d1bcb623452c458dac6b96dee
3
+ metadata.gz: 96866a7042bc2b7082aaeead94c5c90f00448f0b
4
+ data.tar.gz: 42636386ce754b64ce167fe858a59e8c2a0a8286
5
5
  SHA512:
6
- metadata.gz: 5da9ab4636b65d268ed99c45679433c37fe6c7097c7af6c26bbc8a03e08362f3ac6709da209c43950428a6f2b43b1df3a37242e4f28602ca378ec6d40f9063cf
7
- data.tar.gz: d538da07fdd101f86077ad08d2415fc87fab6df2d89327c6df530b56b4f93deaee633095d0fec1633cfc55ae50faa64fb7697614920dcd83bee24a8e33a6b8d3
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.4)
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.2)
85
+ rspec-core (3.1.3)
86
86
  rspec-support (~> 3.1.0)
87
- rspec-expectations (3.1.0)
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(iterator_method, options={}, &block)
35
- raise ArgumentError, 'iterator_method' if iterator_method.nil?
36
- raise NoMethodError, iterator_method unless @executor.respond_to?(iterator_method)
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(iterator_method, *@args) do |*args|
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?
@@ -14,6 +14,7 @@ module Taskinator
14
14
  task.complete!
15
15
  rescue Exception => e
16
16
  task.fail!(e)
17
+ raise e
17
18
  end
18
19
  end
19
20
  end
@@ -282,13 +282,15 @@ module Taskinator
282
282
  if values.is_a?(Array)
283
283
 
284
284
  values = values.collect {|value|
285
- value.respond_to?(:find) ? value.find : value
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
- values[key] = value.find if value.respond_to?(:find)
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
@@ -11,6 +11,7 @@ module Taskinator
11
11
  process.start!
12
12
  rescue Exception => e
13
13
  process.fail!(e)
14
+ raise e
14
15
  end
15
16
  end
16
17
  end
@@ -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
 
@@ -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)
@@ -12,6 +12,7 @@ module Taskinator
12
12
  task.complete! if task.can_complete?
13
13
  rescue Exception => e
14
14
  task.fail!(e)
15
+ raise e
15
16
  end
16
17
  end
17
18
  end
@@ -1,3 +1,3 @@
1
1
  module Taskinator
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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
- it { expect(subject).to respond_to(:enqueue_process) }
13
+ describe "#enqueue_process" do
14
+ it { expect(subject).to respond_to(:enqueue_process) }
13
15
 
14
- it "should enqueue a process" do
15
- expect {
16
- subject.enqueue_process(double('process', :uuid => 'xx-xx-xx-xx'))
17
- }.to_not raise_error
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
- it { expect(subject).to respond_to(:enqueue_task) }
23
+ describe "#enqueue_task" do
24
+ it { expect(subject).to respond_to(:enqueue_task) }
21
25
 
22
- it "should enqueue a task" do
23
- expect {
24
- subject.enqueue_task(double('task', :uuid => 'xx-xx-xx-xx'))
25
- }.to_not raise_error
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
- subject.perform
68
+ expect {
69
+ subject.perform
70
+ }.to raise_error(NotImplementedError)
69
71
  end
70
72
 
71
73
  end
@@ -64,6 +64,11 @@ describe Taskinator::Process do
64
64
  subject.enqueue!
65
65
  expect(subject.current_state.name).to eq(:enqueued)
66
66
  }
67
+ it {
68
+ expect {
69
+ subject.enqueue!
70
+ }.to change { Taskinator.queue.processes.length }.by(1)
71
+ }
67
72
  end
68
73
 
69
74
  describe "#start!" do
@@ -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
- subject.perform
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
- subject.perform
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
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 00:00:00.000000000 Z
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