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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6578169a2c08c2121fa339b741c64d945ad09ef
4
- data.tar.gz: d81d9e9d0e70bfefc38819f0ad6739c6f3972ebb
3
+ metadata.gz: d94784ba92cb1b034270d3889a0f76593841956c
4
+ data.tar.gz: 4f57b758dc57da27127a6bb98819c406af0b3aa0
5
5
  SHA512:
6
- metadata.gz: 25c31e4765d45c157be4e66874c8fb3d89339a855fcdc30c8baab4f1236f37569d9a2f4ff194efaf1e47b2251e2b246e334b33ea96e96f8bf98bd7b53e5cd18c
7
- data.tar.gz: 326f6d5cd8200fc9254fbe3d8c91148ad3b50039bbabd8533000c44a09894eba8195642d96865b28a48d792f5df380dec85f5df6b359416a2722ba0517c68f6d
6
+ metadata.gz: 20b538ab6c57b78f0a22f18f9eb2e52c189ba752eb513d9cce48266c04833767d056073a81ff13c70c562bc6289683af40562dd4e7d9e74f58db70fad5e71ba3
7
+ data.tar.gz: 8f521e1eccd8121c060ea54abbb841259f738de8c9358572ee3e7a3b17afbfec71213d6b1041677c730f65bd9ef34902c420af45f00fd06d06398222e3b566c1
@@ -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
- true
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
- true
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
- true
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,3 +1,3 @@
1
1
  module BlackCompany
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,10 +1,13 @@
1
1
  module BlackCompany
2
2
  class Workhorse
3
- def initialize(queue, exeption_handlers: [])
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?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: black_company
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nownabe