bumbleworks 0.0.63 → 0.0.64
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.
- data/lib/bumbleworks/task.rb +2 -2
- data/lib/bumbleworks/task/finder.rb +34 -35
- data/lib/bumbleworks/version.rb +1 -1
- data/spec/lib/bumbleworks/task_spec.rb +51 -2
- metadata +4 -4
data/lib/bumbleworks/task.rb
CHANGED
@@ -32,9 +32,9 @@ module Bumbleworks
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def method_missing(method, *args)
|
35
|
+
def method_missing(method, *args, &block)
|
36
36
|
if Finder.new.respond_to?(method)
|
37
|
-
return Finder.new([], self).send(method, *args)
|
37
|
+
return Finder.new([], self).send(method, *args, &block)
|
38
38
|
end
|
39
39
|
super
|
40
40
|
end
|
@@ -76,11 +76,10 @@ module Bumbleworks
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def for_entity(entity)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}
|
83
|
-
self
|
79
|
+
with_fields({
|
80
|
+
:entity_type => entity.class.name,
|
81
|
+
:entity_id => entity.identifier
|
82
|
+
})
|
84
83
|
end
|
85
84
|
|
86
85
|
def for_processes(processes)
|
@@ -95,57 +94,57 @@ module Bumbleworks
|
|
95
94
|
for_processes([process])
|
96
95
|
end
|
97
96
|
|
98
|
-
def all
|
99
|
-
return [] if @wfids == []
|
100
|
-
workitems = Bumbleworks.dashboard.context.storage.get_many('workitems', @wfids).select { |wi|
|
101
|
-
@queries.all? { |q| q.call(wi) }
|
102
|
-
}.collect { |wi|
|
103
|
-
::Ruote::Workitem.new(wi)
|
104
|
-
}
|
105
|
-
from_workitems(workitems)
|
106
|
-
end
|
107
|
-
|
108
97
|
def completable(true_or_false = true)
|
109
98
|
@task_filters << proc { |task| task.completable? == true_or_false }
|
110
99
|
self
|
111
100
|
end
|
112
101
|
|
113
|
-
def each(&block)
|
114
|
-
all.each(&block)
|
115
|
-
end
|
116
|
-
|
117
|
-
def empty?
|
118
|
-
all.empty?
|
119
|
-
end
|
120
|
-
|
121
102
|
def next_available(options = {})
|
122
103
|
options[:timeout] ||= Bumbleworks.timeout
|
123
104
|
|
124
105
|
start_time = Time.now
|
125
|
-
while first.nil?
|
106
|
+
while (first_task = first).nil?
|
126
107
|
if (Time.now - start_time) > options[:timeout]
|
127
108
|
raise @task_class::AvailabilityTimeout, "No tasks found matching criteria in time"
|
128
109
|
end
|
129
110
|
sleep 0.1
|
130
111
|
end
|
131
|
-
|
112
|
+
first_task
|
113
|
+
end
|
114
|
+
|
115
|
+
def each
|
116
|
+
return to_enum(:each) unless block_given?
|
117
|
+
return if @wfids == []
|
118
|
+
workitems = Bumbleworks.dashboard.context.storage.get_many('workitems', @wfids).each { |wi|
|
119
|
+
if task = filtered_task_from_raw_workitem(wi)
|
120
|
+
yield task
|
121
|
+
end
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
125
|
+
def all
|
126
|
+
to_a
|
127
|
+
end
|
128
|
+
|
129
|
+
def empty?
|
130
|
+
!any?
|
132
131
|
end
|
133
132
|
|
134
133
|
private
|
135
134
|
|
136
|
-
def
|
137
|
-
@
|
138
|
-
|
139
|
-
|
140
|
-
|
135
|
+
def filtered_task_from_raw_workitem(workitem)
|
136
|
+
if @queries.all? { |q| q.call(workitem) }
|
137
|
+
task = from_workitem(::Ruote::Workitem.new(workitem))
|
138
|
+
task if check_filters(task)
|
139
|
+
end
|
141
140
|
end
|
142
141
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
146
|
-
}.compact
|
142
|
+
def check_filters(task)
|
143
|
+
@task_filters.all? { |f| f.call(task) }
|
144
|
+
end
|
147
145
|
|
148
|
-
|
146
|
+
def from_workitem(workitem)
|
147
|
+
task = @task_class.new(workitem)
|
149
148
|
end
|
150
149
|
end
|
151
150
|
end
|
data/lib/bumbleworks/version.rb
CHANGED
@@ -408,6 +408,43 @@ describe Bumbleworks::Task do
|
|
408
408
|
end
|
409
409
|
end
|
410
410
|
|
411
|
+
context 'iterators' do
|
412
|
+
before :each do
|
413
|
+
Bumbleworks.define_process 'life_on_tha_street' do
|
414
|
+
concurrence do
|
415
|
+
oscar :task => 'grouch_it_up'
|
416
|
+
elmo :task => 'sing_a_tune'
|
417
|
+
elmo :task => 'steal_booze'
|
418
|
+
snuffy :task => 'eat_cabbage'
|
419
|
+
end
|
420
|
+
end
|
421
|
+
Bumbleworks.launch!('life_on_tha_street')
|
422
|
+
Bumbleworks.dashboard.wait_for(:snuffy)
|
423
|
+
end
|
424
|
+
|
425
|
+
describe '.each' do
|
426
|
+
it 'executes for each found task' do
|
427
|
+
list = []
|
428
|
+
described_class.each { |t| list << t.nickname }
|
429
|
+
list.should =~ ['grouch_it_up', 'sing_a_tune', 'steal_booze', 'eat_cabbage']
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
describe '.map' do
|
434
|
+
it 'maps result of yielding block with each task' do
|
435
|
+
list = described_class.map { |t| t.nickname }
|
436
|
+
list.should =~ ['grouch_it_up', 'sing_a_tune', 'steal_booze', 'eat_cabbage']
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
context 'with queries' do
|
441
|
+
it 'checks filters' do
|
442
|
+
list = described_class.for_role('elmo').map { |t| t.nickname }
|
443
|
+
list.should =~ ['sing_a_tune', 'steal_booze']
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
411
448
|
describe '.all' do
|
412
449
|
before :each do
|
413
450
|
Bumbleworks.define_process 'dog-lifecycle' do
|
@@ -506,7 +543,7 @@ describe Bumbleworks::Task do
|
|
506
543
|
end
|
507
544
|
|
508
545
|
describe '.with_fields' do
|
509
|
-
|
546
|
+
before(:each) do
|
510
547
|
Bumbleworks.define_process 'divergination' do
|
511
548
|
concurrence do
|
512
549
|
sequence do
|
@@ -524,12 +561,24 @@ describe Bumbleworks::Task do
|
|
524
561
|
end
|
525
562
|
Bumbleworks.launch!('divergination', :grumbles => true)
|
526
563
|
Bumbleworks.dashboard.wait_for(:loofer)
|
564
|
+
end
|
565
|
+
|
566
|
+
it 'returns all tasks with given field' do
|
527
567
|
described_class.with_fields(:grumbles => true).count.should == 3
|
528
568
|
described_class.with_fields(:bumby => 'fancy').count.should == 1
|
529
569
|
described_class.with_fields(:bumby => 'not_fancy').count.should == 2
|
530
|
-
described_class.with_fields(:grumbles => false, :bumby => 'not_fancy').should be_empty
|
531
570
|
described_class.with_fields(:what => 'ever').should be_empty
|
532
571
|
end
|
572
|
+
|
573
|
+
it 'looks up multiple fields at once' do
|
574
|
+
described_class.with_fields(:grumbles => true, :bumby => 'not_fancy').count.should == 2
|
575
|
+
described_class.with_fields(:grumbles => false, :bumby => 'not_fancy').should be_empty
|
576
|
+
end
|
577
|
+
|
578
|
+
it 'can be chained' do
|
579
|
+
described_class.with_fields(:grumbles => true).with_fields(:bumby => 'fancy').count.should == 1
|
580
|
+
described_class.with_fields(:grumbles => false).with_fields(:bumby => 'not_fancy').should be_empty
|
581
|
+
end
|
533
582
|
end
|
534
583
|
|
535
584
|
describe '.for_entity' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bumbleworks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.64
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-02-
|
15
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: ruote
|
@@ -263,7 +263,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
263
263
|
version: '0'
|
264
264
|
segments:
|
265
265
|
- 0
|
266
|
-
hash:
|
266
|
+
hash: 2850289231226753878
|
267
267
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
268
268
|
none: false
|
269
269
|
requirements:
|
@@ -272,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
272
|
version: '0'
|
273
273
|
segments:
|
274
274
|
- 0
|
275
|
-
hash:
|
275
|
+
hash: 2850289231226753878
|
276
276
|
requirements: []
|
277
277
|
rubyforge_project:
|
278
278
|
rubygems_version: 1.8.23
|