oni 4.1.2 → 4.2.0

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
- SHA1:
3
- metadata.gz: 778857ec8997102b397020f4a79c2eca7e4c9e80
4
- data.tar.gz: 0da85c03874b6cc14fb7fe94d948022e3a2104b0
2
+ SHA256:
3
+ metadata.gz: 416abd59b70ff8bd2f2a98b03afc9c714ada232b409036ff973455091954c4aa
4
+ data.tar.gz: e4b779b2255b95f396ca3d66e82b4f9b3766a9768ad00949a2fad3446026dba5
5
5
  SHA512:
6
- metadata.gz: d49cd26b892b851e5a1ba770d11978780632723fab878146cd9686c703585c76cb3576e4d61e096b9f275f8db1975eec65abc0198382b80d0f4e28cd36afa31c
7
- data.tar.gz: 516665bc4b5d18b0a483ba71a18692a3645e297e9f269189fdd25e64ce88b1bf44358ca3f36870fcd35b19158bb7c1b7c04e8749726374ef0f0705c6a838176e
6
+ metadata.gz: cf9380fae049e874030a9909977328806203578ed5aa72331ea343e8c081b139d36527b5aba921a8e261865c247a018ecbc97004ff7f497dc2b0d99f4385b1b0
7
+ data.tar.gz: 60267682fe360ecd126f352ab26946c5413f18bf36e2059fe7751a65ea8c987451dfeda92982a22e89ca5512d3f6ab9b38dacd81f1782d44ba48f0173d78ac1f
@@ -38,12 +38,9 @@ module Oni
38
38
  #
39
39
  def option(name, default = nil)
40
40
  value = self.class.options[name.to_sym]
41
+ value = default if default and !value
41
42
 
42
- if default and !value
43
- value = default
44
- end
45
-
46
- return value.respond_to?(:call) ? value.call : value
43
+ if value.respond_to? :call then value.call else value end
47
44
  end
48
45
 
49
46
  ##
@@ -102,6 +99,7 @@ module Oni
102
99
  set(option, value)
103
100
  end
104
101
  end
105
- end # ClassMethods
106
- end # Configurable
107
- end # Oni
102
+
103
+ end
104
+ end
105
+ end
data/lib/oni/daemon.rb CHANGED
@@ -13,7 +13,14 @@ module Oni
13
13
  class Daemon
14
14
  include Configurable
15
15
 
16
- attr_reader :workers
16
+ attr_reader :daemon_workers
17
+
18
+ ##
19
+ # The default amount of worker to start.
20
+ #
21
+ # @return [Fixnum]
22
+ #
23
+ DEFAULT_WORKER_AMOUNT = 1
17
24
 
18
25
  ##
19
26
  # The default amount of threads to start.
@@ -34,7 +41,7 @@ module Oni
34
41
  # is defined.
35
42
  #
36
43
  def initialize
37
- @workers = []
44
+ @daemon_workers = {}
38
45
 
39
46
  after_initialize if respond_to?(:after_initialize)
40
47
  end
@@ -50,14 +57,13 @@ module Oni
50
57
  before_start if respond_to?(:before_start)
51
58
 
52
59
  if threads > 0
53
- threads.times do
54
- workers << spawn_thread
60
+ if workers > 1
61
+ workers.times{ |i| fork{ spawn_worker i } }
62
+ Process.waitall
63
+ else
64
+ spawn_worker
55
65
  end
56
-
57
- workers.each(&:join)
58
-
59
- # If we don't have any threads run in non threaded mode.
60
- else
66
+ else # If we don't have any threads run in non threaded mode.
61
67
  run_thread
62
68
  end
63
69
  rescue => error
@@ -70,8 +76,14 @@ module Oni
70
76
  # be shut down *immediately*.
71
77
  #
72
78
  def stop
73
- workers.each(&:kill)
74
- workers.clear
79
+ daemon_workers.each do |pid, worker_threads|
80
+ worker_threads.each(&:kill)
81
+ worker_threads.clear
82
+ end
83
+ end
84
+
85
+ def workers
86
+ option :workers, DEFAULT_WORKER_AMOUNT
75
87
  end
76
88
 
77
89
  ##
@@ -80,7 +92,7 @@ module Oni
80
92
  # @return [Fixnum]
81
93
  #
82
94
  def threads
83
- return option(:threads, DEFAULT_THREAD_AMOUNT)
95
+ option :threads, DEFAULT_THREAD_AMOUNT
84
96
  end
85
97
 
86
98
  ##
@@ -168,6 +180,19 @@ module Oni
168
180
  return option(:mapper).new
169
181
  end
170
182
 
183
+ ##
184
+ # Spawns a new thread that waits for daemon input.
185
+ #
186
+ # @return [Thread]
187
+ #
188
+ def spawn_worker i = nil
189
+ Process.setproctitle "#{$0}: worker #{i}" if i
190
+
191
+ daemon_workers[Process.pid] = Array.new threads do
192
+ spawn_thread
193
+ end.each(&:join)
194
+ end
195
+
171
196
  ##
172
197
  # Spawns a new thread that waits for daemon input.
173
198
  #
@@ -198,5 +223,6 @@ module Oni
198
223
 
199
224
  retry
200
225
  end
201
- end # Daemon
202
- end # Oni
226
+
227
+ end
228
+ end
@@ -71,6 +71,7 @@ module Oni
71
71
 
72
72
  return response.queue_url
73
73
  end
74
- end # SQS
75
- end # Daemons
76
- end # Oni
74
+
75
+ end
76
+ end
77
+ end
data/lib/oni/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oni
2
- VERSION = '4.1.2'
2
+ VERSION = '4.2.0'
3
3
  end # Oni
data/oni.gemspec CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |gem|
10
10
 
11
11
  gem.summary = 'Framework for building concurrent daemons in Ruby.'
12
12
  gem.description = gem.summary
13
- gem.has_rdoc = 'yard'
14
13
  gem.license = 'MIT'
15
14
 
16
15
  gem.required_ruby_version = '>= 1.9.3'
@@ -30,5 +29,6 @@ Gem::Specification.new do |gem|
30
29
  gem.add_development_dependency 'yard'
31
30
  gem.add_development_dependency 'simplecov'
32
31
  gem.add_development_dependency 'kramdown'
32
+ gem.add_development_dependency 'pry'
33
33
  gem.add_development_dependency 'aws-sdk', '~> 2.0'
34
34
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oni
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yorick Peterse
8
8
  - Wilco van Duinkerken
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-11 00:00:00.000000000 Z
12
+ date: 2021-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -95,6 +95,20 @@ dependencies:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
98
112
  - !ruby/object:Gem::Dependency
99
113
  name: aws-sdk
100
114
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +124,7 @@ dependencies:
110
124
  - !ruby/object:Gem::Version
111
125
  version: '2.0'
112
126
  description: Framework for building concurrent daemons in Ruby.
113
- email:
127
+ email:
114
128
  executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
@@ -129,11 +143,11 @@ files:
129
143
  - lib/oni/worker.rb
130
144
  - lib/oni/wrapped_error.rb
131
145
  - oni.gemspec
132
- homepage:
146
+ homepage:
133
147
  licenses:
134
148
  - MIT
135
149
  metadata: {}
136
- post_install_message:
150
+ post_install_message:
137
151
  rdoc_options: []
138
152
  require_paths:
139
153
  - lib
@@ -148,9 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
162
  - !ruby/object:Gem::Version
149
163
  version: '0'
150
164
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.6.13
153
- signing_key:
165
+ rubygems_version: 3.0.9
166
+ signing_key:
154
167
  specification_version: 4
155
168
  summary: Framework for building concurrent daemons in Ruby.
156
169
  test_files: []