black_company 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/black_company/pool.rb +11 -6
- data/lib/black_company/version.rb +1 -1
- data/lib/black_company/workhorse.rb +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d94784ba92cb1b034270d3889a0f76593841956c
|
4
|
+
data.tar.gz: 4f57b758dc57da27127a6bb98819c406af0b3aa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20b538ab6c57b78f0a22f18f9eb2e52c189ba752eb513d9cce48266c04833767d056073a81ff13c70c562bc6289683af40562dd4e7d9e74f58db70fad5e71ba3
|
7
|
+
data.tar.gz: 8f521e1eccd8121c060ea54abbb841259f738de8c9358572ee3e7a3b17afbfec71213d6b1041677c730f65bd9ef34902c420af45f00fd06d06398222e3b566c1
|
data/lib/black_company/pool.rb
CHANGED
@@ -6,19 +6,21 @@ module BlackCompany
|
|
6
6
|
class Pool
|
7
7
|
DEFAULT_POOL_SIZE = 20
|
8
8
|
|
9
|
-
attr_reader :workhorse_class, :exeption_handlers
|
9
|
+
attr_reader :workhorse_class, :exeption_handlers, :options
|
10
10
|
|
11
11
|
def initialize(
|
12
12
|
pool_size: DEFAULT_POOL_SIZE,
|
13
13
|
queue_size: nil,
|
14
14
|
workhorse_class: Workhorse,
|
15
|
-
exeption_handlers: []
|
15
|
+
exeption_handlers: [],
|
16
|
+
options: {}
|
16
17
|
)
|
17
18
|
|
18
19
|
@queue = queue_size ? SizedQueue.new(queue_size) : Queue.new
|
19
20
|
@fired_queue = Queue.new
|
20
21
|
@workhorse_class = workhorse_class
|
21
22
|
@exeption_handlers = exeption_handlers
|
23
|
+
@options = options
|
22
24
|
|
23
25
|
@workhorses = []
|
24
26
|
hire(pool_size)
|
@@ -30,6 +32,7 @@ module BlackCompany
|
|
30
32
|
alias_method :size, :count
|
31
33
|
|
32
34
|
def fire(count)
|
35
|
+
count = [count, self.count].max
|
33
36
|
count.times { @queue.push(Event.new(:terminate, @fired_queue)) }
|
34
37
|
fired_count = 0
|
35
38
|
while fired_count != count
|
@@ -39,14 +42,14 @@ module BlackCompany
|
|
39
42
|
fired_count += 1
|
40
43
|
end
|
41
44
|
|
42
|
-
|
45
|
+
count
|
43
46
|
end
|
44
47
|
|
45
48
|
def hire(count)
|
46
49
|
workhorses = Array.new(count) { hire_one }
|
47
50
|
@workhorses.concat(workhorses)
|
48
51
|
|
49
|
-
|
52
|
+
count
|
50
53
|
end
|
51
54
|
|
52
55
|
def inspect
|
@@ -60,11 +63,13 @@ module BlackCompany
|
|
60
63
|
@exeption_handlers << block
|
61
64
|
@workhorses.each { |w| w.on_exeption(&block) }
|
62
65
|
|
63
|
-
|
66
|
+
nil
|
64
67
|
end
|
65
68
|
|
66
69
|
def receive(task_content = nil, &block)
|
67
70
|
@queue.push(Event.new(:perform, Task.new(task_content, &block)))
|
71
|
+
|
72
|
+
nil
|
68
73
|
end
|
69
74
|
|
70
75
|
def queued_tasks_size
|
@@ -78,7 +83,7 @@ module BlackCompany
|
|
78
83
|
private
|
79
84
|
|
80
85
|
def hire_one
|
81
|
-
workhorse_class.new(@queue, exeption_handlers: exeption_handlers)
|
86
|
+
workhorse_class.new(@queue, exeption_handlers: exeption_handlers, options: options)
|
82
87
|
end
|
83
88
|
end
|
84
89
|
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
module BlackCompany
|
2
2
|
class Workhorse
|
3
|
-
|
3
|
+
attr_reader :options
|
4
|
+
|
5
|
+
def initialize(queue, exeption_handlers: [], options: {})
|
4
6
|
@queue = queue
|
5
7
|
@active = true
|
6
8
|
@thread = Thread.new { work }
|
7
9
|
@exeption_handlers = [*exeption_handlers]
|
10
|
+
@options = options
|
8
11
|
end
|
9
12
|
|
10
13
|
def alive?
|