opener-daemons 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/LICENSE.txt +10 -19
- data/lib/opener/daemons.rb +1 -0
- data/lib/opener/daemons/daemon.rb +37 -8
- data/lib/opener/daemons/sqs.rb +18 -2
- data/lib/opener/daemons/version.rb +1 -1
- data/opener-daemons.gemspec +3 -2
- metadata +58 -50
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MzllZTE4ODlhOGU4M2QzNmE4NDcyOTM0MTNmN2E0ZWU0ODU1MGZhOA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 983e879dcaa50627ad0893e28d50d70f69fd77c3
|
4
|
+
data.tar.gz: 9c6cf436bc1c7aee5a78d3b62adcd220df334b02
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NGQ5ZWExNjE0ZDQyYzZmNmY2ZDU1NzIwZTgxNjk5ODg4MzFhNWE5OTNhMGI5
|
11
|
-
YzhmYWRjNzA3NzczOGUyNjZiN2ExNzhlNGNiZWZiZDY0NTEwNGI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ODdjNmYwYjVjYmY5NzU5MjliMGE5MWQ2NWY2OWNmZTNlMTA3MmM3Yjk5ODA4
|
14
|
-
OGQwNDcxYmU5NTVhYmVlNjFjNTBlZjU4NGE2NWM3MGNhODJmYTRmNWE1OWRk
|
15
|
-
NjEzMGFlMDY3M2FmOTEyOWQ0MzRjYmNiYWJlMTU1N2UyMjI1ZGQ=
|
6
|
+
metadata.gz: 77b310b5014d001ab149822d64fba94e1b0553ac95609b6f56ef7e77cba507792db17163c0832aa79cf24faa8117497c758c2853f86ae862c63f79f7158f8eef
|
7
|
+
data.tar.gz: 4cdab83d98edf62ce78cd9a2003d61c6b44bcd060235be307bf4f7023b24e293863ac8c7432b8b60b05a99256b874e686d0b73635a4386964f392d46e93e3d40
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,13 @@
|
|
1
|
-
Copyright
|
1
|
+
Copyright 2014 OpeNER Project Consortium
|
2
2
|
|
3
|
-
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
4
6
|
|
5
|
-
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/lib/opener/daemons.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'thread'
|
2
4
|
require 'opener/daemons/sqs'
|
3
5
|
require 'json'
|
@@ -58,7 +60,6 @@ module Opener
|
|
58
60
|
def buffer_new_messages
|
59
61
|
return if input_buffer.size > buffer_size
|
60
62
|
return if output_buffer.size > buffer_size
|
61
|
-
|
62
63
|
messages = input_queue.receive_messages(batch_size)
|
63
64
|
|
64
65
|
if messages.nil?
|
@@ -103,7 +104,7 @@ module Opener
|
|
103
104
|
loop do
|
104
105
|
message = input_buffer.pop
|
105
106
|
|
106
|
-
input =
|
107
|
+
input = message[:body]["input"]
|
107
108
|
input,* = input if input.kind_of?(Array)
|
108
109
|
|
109
110
|
begin
|
@@ -119,9 +120,11 @@ module Opener
|
|
119
120
|
output = input
|
120
121
|
end
|
121
122
|
end
|
122
|
-
|
123
|
-
output_buffer.push({ :output=>output,
|
124
|
-
:
|
123
|
+
message[:body].delete("input")
|
124
|
+
output_buffer.push({ :output=>output,
|
125
|
+
:body => message[:body],
|
126
|
+
:handle=>message[:receipt_handle]
|
127
|
+
})
|
125
128
|
end
|
126
129
|
end
|
127
130
|
end
|
@@ -133,10 +136,22 @@ module Opener
|
|
133
136
|
logger.info "Pusher #{t+1} ready for action..."
|
134
137
|
loop do
|
135
138
|
message = output_buffer.pop
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
+
callbacks = extract_callbacks(message[:body]["callbacks[]"])
|
140
|
+
handler = Opener::CallbackHandler.new
|
141
|
+
message[:body][:input] = message[:output].force_encoding("UTF-8")
|
142
|
+
|
143
|
+
|
144
|
+
unless callbacks.empty?
|
145
|
+
callback_url = callbacks.shift
|
146
|
+
message[:body][:'callbacks[]'] = callbacks
|
147
|
+
payload = {:body => message[:body]}
|
148
|
+
handler.post(callback_url, payload)
|
149
|
+
else
|
150
|
+
payload = {:body => message[:body]}
|
151
|
+
handler.post(output_queue.queue_url, payload)
|
152
|
+
end
|
139
153
|
input_queue.delete_message(message[:handle])
|
154
|
+
|
140
155
|
end
|
141
156
|
end
|
142
157
|
end
|
@@ -174,6 +189,20 @@ module Opener
|
|
174
189
|
def relentless?
|
175
190
|
@relentless
|
176
191
|
end
|
192
|
+
|
193
|
+
##
|
194
|
+
# Returns an Array containing the callback URLs, ignoring empty values.
|
195
|
+
#
|
196
|
+
# @param [Array|String] input
|
197
|
+
# @return [Array]
|
198
|
+
#
|
199
|
+
def extract_callbacks(input)
|
200
|
+
return [] if input.nil? || input.empty?
|
201
|
+
|
202
|
+
callbacks = input.compact.reject(&:empty?)
|
203
|
+
|
204
|
+
return callbacks
|
205
|
+
end
|
177
206
|
|
178
207
|
end
|
179
208
|
end
|
data/lib/opener/daemons/sqs.rb
CHANGED
@@ -10,7 +10,7 @@ module Opener
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(name)
|
13
|
-
@sqs = Aws::SQS.new
|
13
|
+
@sqs = Aws::SQS::Client.new
|
14
14
|
@name = name
|
15
15
|
begin
|
16
16
|
@url = sqs.get_queue_url(:queue_name=>name)[:queue_url]
|
@@ -30,7 +30,23 @@ module Opener
|
|
30
30
|
|
31
31
|
def receive_messages(limit)
|
32
32
|
result = sqs.receive_message(:queue_url=>url,
|
33
|
-
:max_number_of_messages=>limit)[:messages]
|
33
|
+
:max_number_of_messages=>limit)[:messages] rescue []
|
34
|
+
|
35
|
+
result ? to_hash(result) : []
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_hash(messages)
|
40
|
+
messages.map do |m|
|
41
|
+
hash = m.to_hash
|
42
|
+
json_body = JSON.parse(hash.delete(:body))
|
43
|
+
hash[:body] = json_body["body"] ? json_body["body"] : json_body
|
44
|
+
hash
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def queue_url
|
49
|
+
url
|
34
50
|
end
|
35
51
|
|
36
52
|
end
|
data/opener-daemons.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.summary = %q{Daemonize OpeNER components and make them read from an SQS queue. JRuby compatible.}
|
9
9
|
spec.description = spec.summary
|
10
10
|
spec.homepage = "http://opener-project.github.io"
|
11
|
-
spec.license = "Apache
|
11
|
+
spec.license = "Apache 2.0"
|
12
12
|
|
13
13
|
spec.files = Dir.glob([
|
14
14
|
'lib/**/*',
|
@@ -17,9 +17,10 @@ Gem::Specification.new do |spec|
|
|
17
17
|
'README.md'
|
18
18
|
]).select { |file| File.basename(file) }
|
19
19
|
|
20
|
-
spec.add_dependency 'aws-sdk-core'
|
20
|
+
spec.add_dependency 'aws-sdk-core'
|
21
21
|
spec.add_dependency 'spoon'
|
22
22
|
spec.add_dependency 'dotenv'
|
23
|
+
spec.add_dependency "opener-callback-handler"
|
23
24
|
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.5"
|
25
26
|
spec.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,144 +1,152 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opener-daemons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilco van Duinkerken
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
15
|
-
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
|
19
|
+
version: '0'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '>='
|
21
23
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
23
|
-
type: :runtime
|
24
|
+
version: '0'
|
24
25
|
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: spoon
|
25
29
|
version_requirements: !ruby/object:Gem::Requirement
|
26
30
|
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 2.0.0.rc1
|
30
|
-
- - <
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: spoon
|
33
|
+
version: '0'
|
35
34
|
requirement: !ruby/object:Gem::Requirement
|
36
35
|
requirements:
|
37
|
-
- -
|
36
|
+
- - '>='
|
38
37
|
- !ruby/object:Gem::Version
|
39
38
|
version: '0'
|
40
|
-
type: :runtime
|
41
39
|
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
42
43
|
version_requirements: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
|
-
- -
|
45
|
+
- - '>='
|
45
46
|
- !ruby/object:Gem::Version
|
46
47
|
version: '0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: dotenv
|
49
48
|
requirement: !ruby/object:Gem::Requirement
|
50
49
|
requirements:
|
51
|
-
- -
|
50
|
+
- - '>='
|
52
51
|
- !ruby/object:Gem::Version
|
53
52
|
version: '0'
|
54
|
-
type: :runtime
|
55
53
|
prerelease: false
|
54
|
+
type: :runtime
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: opener-callback-handler
|
56
57
|
version_requirements: !ruby/object:Gem::Requirement
|
57
58
|
requirements:
|
58
|
-
- -
|
59
|
+
- - '>='
|
59
60
|
- !ruby/object:Gem::Version
|
60
61
|
version: '0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: bundler
|
63
62
|
requirement: !ruby/object:Gem::Requirement
|
64
63
|
requirements:
|
65
|
-
- -
|
64
|
+
- - '>='
|
66
65
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
68
|
-
type: :development
|
66
|
+
version: '0'
|
69
67
|
prerelease: false
|
68
|
+
type: :runtime
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
70
71
|
version_requirements: !ruby/object:Gem::Requirement
|
71
72
|
requirements:
|
72
73
|
- - ~>
|
73
74
|
- !ruby/object:Gem::Version
|
74
75
|
version: '1.5'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: rake
|
77
76
|
requirement: !ruby/object:Gem::Requirement
|
78
77
|
requirements:
|
79
|
-
- -
|
78
|
+
- - ~>
|
80
79
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
82
|
-
type: :development
|
80
|
+
version: '1.5'
|
83
81
|
prerelease: false
|
82
|
+
type: :development
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
84
85
|
version_requirements: !ruby/object:Gem::Requirement
|
85
86
|
requirements:
|
86
|
-
- -
|
87
|
+
- - '>='
|
87
88
|
- !ruby/object:Gem::Version
|
88
89
|
version: '0'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: rspec
|
91
90
|
requirement: !ruby/object:Gem::Requirement
|
92
91
|
requirements:
|
93
|
-
- -
|
92
|
+
- - '>='
|
94
93
|
- !ruby/object:Gem::Version
|
95
94
|
version: '0'
|
96
|
-
type: :development
|
97
95
|
prerelease: false
|
96
|
+
type: :development
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
98
99
|
version_requirements: !ruby/object:Gem::Requirement
|
99
100
|
requirements:
|
100
|
-
- -
|
101
|
+
- - '>='
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
|
-
|
104
|
-
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
prerelease: false
|
110
|
+
type: :development
|
111
|
+
description: Daemonize OpeNER components and make them read from an SQS queue. JRuby compatible.
|
105
112
|
email:
|
106
113
|
- wilco@sparkboxx.com
|
107
114
|
executables: []
|
108
115
|
extensions: []
|
109
116
|
extra_rdoc_files: []
|
110
117
|
files:
|
118
|
+
- lib/opener/daemons.rb
|
111
119
|
- lib/opener/daemons/controller.rb
|
112
120
|
- lib/opener/daemons/daemon.rb
|
113
121
|
- lib/opener/daemons/opt_parser.rb
|
114
122
|
- lib/opener/daemons/sqs.rb
|
115
123
|
- lib/opener/daemons/version.rb
|
116
|
-
- lib/opener/daemons.rb
|
117
124
|
- LICENSE.txt
|
118
125
|
- opener-daemons.gemspec
|
119
126
|
- README.md
|
120
127
|
homepage: http://opener-project.github.io
|
121
128
|
licenses:
|
122
|
-
- Apache
|
129
|
+
- Apache 2.0
|
123
130
|
metadata: {}
|
124
|
-
post_install_message:
|
131
|
+
post_install_message:
|
125
132
|
rdoc_options: []
|
126
133
|
require_paths:
|
127
134
|
- lib
|
128
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
136
|
requirements:
|
130
|
-
- -
|
137
|
+
- - '>='
|
131
138
|
- !ruby/object:Gem::Version
|
132
139
|
version: '0'
|
133
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
141
|
requirements:
|
135
|
-
- -
|
142
|
+
- - '>='
|
136
143
|
- !ruby/object:Gem::Version
|
137
144
|
version: '0'
|
138
145
|
requirements: []
|
139
|
-
rubyforge_project:
|
140
|
-
rubygems_version: 2.1.
|
141
|
-
signing_key:
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.1.9
|
148
|
+
signing_key:
|
142
149
|
specification_version: 4
|
143
150
|
summary: Daemonize OpeNER components and make them read from an SQS queue. JRuby compatible.
|
144
151
|
test_files: []
|
152
|
+
has_rdoc:
|