taskbag 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +9 -0
- data/README.md +4 -2
- data/lib/taskbag.rb +8 -0
- data/lib/taskbag/bag.rb +8 -0
- data/lib/taskbag/version.rb +1 -1
- data/spec/bag_spec.rb +91 -76
- data/spec/taskbag_spec.rb +26 -0
- metadata +17 -22
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6616c9985c2c790afcb154a3cbd4712c54486033
|
4
|
+
data.tar.gz: 545ed492816ecc0247efec8950e66669e0d05174
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 458768e9b9c0c79797b690458a1cf82aacd8ebafcf6a55f3ed8c03479da40f84e7b597d0a063d513ee83b89f0ad049110eab2ce3bf74dbbce87d9f207f289831
|
7
|
+
data.tar.gz: 5b2f71e994403c7bcc1046becdb7ca0d8c50e5fa59bde3a62a6d5cc07317384b6802105961b9670281c70de69ea71f84d5cec50f3a52066843fbfee141f2eab1
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# TaskBag
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/taskbag.png)](http://badge.fury.io/rb/taskbag)
|
2
3
|
|
3
4
|
A super simple implementation of the Bag-of-Tasks Paradigm [1].
|
4
5
|
|
@@ -31,7 +32,7 @@ In TaskBag you can actually have different tasks in the same bag.
|
|
31
32
|
|
32
33
|
### When not to use it
|
33
34
|
|
34
|
-
If you
|
35
|
+
If you're not in the above situation.
|
35
36
|
|
36
37
|
### How to use it
|
37
38
|
|
@@ -77,4 +78,5 @@ As said before, you can add more tasks as the result of a job, for example, if y
|
|
77
78
|
## References
|
78
79
|
|
79
80
|
[1] http://www.cs.arizona.edu/~greg/mpdbook/glossary.html
|
80
|
-
|
81
|
+
|
82
|
+
[2] http://www.eead.csic.es/compbio/material/programacion_rocks/pics/paral_tareas.pdf
|
data/lib/taskbag.rb
CHANGED
data/lib/taskbag/bag.rb
CHANGED
data/lib/taskbag/version.rb
CHANGED
data/spec/bag_spec.rb
CHANGED
@@ -1,79 +1,94 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe TaskBag::Bag do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
4
|
+
let(:mocked_queue) { double('mocked queue', empty?: true) }
|
5
|
+
subject { TaskBag::Bag.new }
|
6
|
+
|
7
|
+
it { should be_closed }
|
8
|
+
|
9
|
+
describe '.open' do
|
10
|
+
subject { TaskBag::Bag.open(5) }
|
11
|
+
|
12
|
+
it { should_not be_closed }
|
13
|
+
|
14
|
+
it 'is opened with the given number of workers' do
|
15
|
+
subject.nworkers.should == 5
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'opening a bag' do
|
20
|
+
it 'makes the bag open' do
|
21
|
+
subject.open 0
|
22
|
+
subject.should_not be_closed
|
23
|
+
subject.close!
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'raises an exception if already open' do
|
27
|
+
subject.open 0
|
28
|
+
expect { subject.open(0) }.to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'creates the given number of workers in different threads' do
|
32
|
+
TaskBag::Worker.should_receive(:start)
|
33
|
+
.with(subject)
|
34
|
+
.exactly(3).times
|
35
|
+
.and_return 1, 2, 3
|
36
|
+
|
37
|
+
subject.open(3).should have(3).items
|
38
|
+
subject.close!
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'is opened with the given number of workers' do
|
42
|
+
subject.open 10
|
43
|
+
subject.nworkers.should == 10
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'closing a bag' do
|
48
|
+
subject { TaskBag::Bag.new(mocked_queue) }
|
49
|
+
|
50
|
+
it 'should be closed after' do
|
51
|
+
mocked_queue.should_receive(:empty?).and_return true
|
52
|
+
subject.open 0
|
53
|
+
subject.close!
|
54
|
+
subject.should be_closed
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'raises an exception if already closed' do
|
58
|
+
expect { subject.close! }.to raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'waits for all jobs to be passed to workers before closing' do
|
62
|
+
mocked_queue.should_receive(:empty?).and_return false, false, true
|
63
|
+
subject.open 0
|
64
|
+
subject.close!
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'a full bag' do
|
68
|
+
subject { TaskBag::Bag.new }
|
69
|
+
it 'waits for every worker to finish before it closes' do
|
70
|
+
finished = 0
|
71
|
+
job = double('job')
|
72
|
+
job.stub :run do
|
73
|
+
sleep 0.5
|
74
|
+
finished += 1
|
75
|
+
end
|
76
|
+
subject.open 2
|
77
|
+
subject.add job
|
78
|
+
subject.add job
|
79
|
+
subject.add job
|
80
|
+
subject.close!
|
81
|
+
finished.should == 3
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'execute the jobs in a FIFO fashion' do
|
87
|
+
subject.add 1
|
88
|
+
subject.add 2
|
89
|
+
|
90
|
+
subject.next.should be 1
|
91
|
+
subject.next.should be 2
|
92
|
+
subject.next.should be_nil
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TaskBag do
|
4
|
+
let(:bag) { double('task bag') }
|
5
|
+
around {|example| TaskBag.work(10, &example)}
|
6
|
+
|
7
|
+
describe '.work' do
|
8
|
+
it 'opens a bag with the given number of workers' do
|
9
|
+
allow(bag).to receive(:close!)
|
10
|
+
expect(TaskBag::Bag).to receive(:open).with(10) { bag }
|
11
|
+
|
12
|
+
TaskBag.work(10) do |b|
|
13
|
+
expect(b).to be bag
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'closes the bag after it is done with the given block' do
|
18
|
+
allow(TaskBag::Bag).to receive(:open).and_return(bag)
|
19
|
+
TaskBag.work(10) do |b|
|
20
|
+
# This will guarantee that the close! method will only
|
21
|
+
# be called after this block is completed
|
22
|
+
expect(bag).to receive(:close!)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taskbag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Carlos Palhares
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.3'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.3'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: A simplistic task of bags implementation for multithreaded scripts
|
@@ -65,7 +58,8 @@ executables: []
|
|
65
58
|
extensions: []
|
66
59
|
extra_rdoc_files: []
|
67
60
|
files:
|
68
|
-
- .gitignore
|
61
|
+
- ".gitignore"
|
62
|
+
- ".travis.yml"
|
69
63
|
- Gemfile
|
70
64
|
- LICENSE.txt
|
71
65
|
- README.md
|
@@ -76,34 +70,35 @@ files:
|
|
76
70
|
- lib/taskbag/worker.rb
|
77
71
|
- spec/bag_spec.rb
|
78
72
|
- spec/spec_helper.rb
|
73
|
+
- spec/taskbag_spec.rb
|
79
74
|
- spec/worker_spec.rb
|
80
75
|
- taskbag.gemspec
|
81
76
|
homepage: https://github.com/xjunior/taskbag
|
82
77
|
licenses:
|
83
78
|
- MIT
|
79
|
+
metadata: {}
|
84
80
|
post_install_message:
|
85
81
|
rdoc_options: []
|
86
82
|
require_paths:
|
87
83
|
- lib
|
88
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
85
|
requirements:
|
91
|
-
- -
|
86
|
+
- - ">="
|
92
87
|
- !ruby/object:Gem::Version
|
93
88
|
version: '0'
|
94
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
90
|
requirements:
|
97
|
-
- -
|
91
|
+
- - ">="
|
98
92
|
- !ruby/object:Gem::Version
|
99
93
|
version: '0'
|
100
94
|
requirements: []
|
101
95
|
rubyforge_project:
|
102
|
-
rubygems_version:
|
96
|
+
rubygems_version: 2.2.2
|
103
97
|
signing_key:
|
104
|
-
specification_version:
|
98
|
+
specification_version: 4
|
105
99
|
summary: A simplistic task of bags implementation for multithreaded scripts
|
106
100
|
test_files:
|
107
101
|
- spec/bag_spec.rb
|
108
102
|
- spec/spec_helper.rb
|
103
|
+
- spec/taskbag_spec.rb
|
109
104
|
- spec/worker_spec.rb
|