opener-daemons 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/opener/daemons/configuration.rb +20 -4
- data/lib/opener/daemons/daemon.rb +9 -4
- data/lib/opener/daemons/mapper.rb +9 -4
- data/lib/opener/daemons/version.rb +1 -1
- data/lib/opener/daemons/worker.rb +1 -2
- 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: cd43444725d72e2076b674d5c1a4ae46b7c2a514
|
4
|
+
data.tar.gz: a315f9989260c5c36efbe29d412120abcef97802
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29f9b444314f438ab37d2732f2d3dd115993122a31bc4dd63b3b2b7e98d6b4a8d12ff2f159fc57b16d501635d8d05db244717af95874ab4243a87be49c211f5a
|
7
|
+
data.tar.gz: 0f9ce2a6d61f73eeac95b24045b75dfe628e2bdad9ce3e780fa50a287d63597e8138ca44d2f11455b343d22c1d85f8e403aff3dc7597b0e60b523c64039c8f06
|
data/README.md
CHANGED
@@ -58,9 +58,12 @@ corresponding constant. For example, for the language identifier:
|
|
58
58
|
|
59
59
|
daemon.start
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
Extra arguments for the component can be specified as a Hash in the second
|
62
|
+
argument of the `Daemon.new` method:
|
63
|
+
|
64
|
+
daemon = Opener::Daemons::Daemon.new(Opener::LanguageIdentifier, :kaf => false)
|
65
|
+
|
66
|
+
These options will be passed to every individual instance of the component.
|
64
67
|
|
65
68
|
## Requirements
|
66
69
|
|
@@ -6,6 +6,9 @@ module Opener
|
|
6
6
|
# @!attribute [r] component
|
7
7
|
# @return [Class]
|
8
8
|
#
|
9
|
+
# @!attribute [r] component_options
|
10
|
+
# @return [Hash]
|
11
|
+
#
|
9
12
|
# @!attribute [r] input_url
|
10
13
|
# @return [String]
|
11
14
|
#
|
@@ -16,10 +19,13 @@ module Opener
|
|
16
19
|
# @return [Hash]
|
17
20
|
#
|
18
21
|
class Configuration
|
19
|
-
attr_reader :component, :input_url, :callbacks,
|
22
|
+
attr_reader :component, :component_options, :input_url, :callbacks,
|
23
|
+
:metadata
|
20
24
|
|
21
25
|
##
|
22
|
-
# @param [Class] component
|
26
|
+
# @param [Class] component The component to use.
|
27
|
+
# @param [Hash] component_options Options to pass to the component.
|
28
|
+
#
|
23
29
|
# @param [Hash] options
|
24
30
|
#
|
25
31
|
# @option options [String] :input_url
|
@@ -27,8 +33,9 @@ module Opener
|
|
27
33
|
# @option options [Array] :callbacks
|
28
34
|
# @option options [Hash] :metadata
|
29
35
|
#
|
30
|
-
def initialize(component, options = {})
|
31
|
-
@component
|
36
|
+
def initialize(component, component_options = {}, options = {})
|
37
|
+
@component = component
|
38
|
+
@component_options = component_options
|
32
39
|
|
33
40
|
options.each do |key, value|
|
34
41
|
instance_variable_set("@#{key}", value) if respond_to?(key)
|
@@ -47,6 +54,15 @@ module Opener
|
|
47
54
|
def identifier
|
48
55
|
return @identifier ||= SecureRandom.hex
|
49
56
|
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Returns a new instance of the component.
|
60
|
+
#
|
61
|
+
# @return [Object]
|
62
|
+
#
|
63
|
+
def component_instance
|
64
|
+
return component.new(component_options)
|
65
|
+
end
|
50
66
|
end # Configuration
|
51
67
|
end # Daemons
|
52
68
|
end # Opener
|
@@ -7,8 +7,11 @@ module Opener
|
|
7
7
|
# @!attribute [r] component
|
8
8
|
# @return [Class]
|
9
9
|
#
|
10
|
+
# @!attribute [r] component_options
|
11
|
+
# @return [Hash]
|
12
|
+
#
|
10
13
|
class Daemon < Oni::Daemons::SQS
|
11
|
-
attr_reader :component
|
14
|
+
attr_reader :component, :component_options
|
12
15
|
|
13
16
|
set :worker, Worker
|
14
17
|
set :mapper, Mapper
|
@@ -21,9 +24,11 @@ module Opener
|
|
21
24
|
|
22
25
|
##
|
23
26
|
# @param [Class] component The component to run in the worker.
|
27
|
+
# @param [Hash] options Extra options to pass to the component.
|
24
28
|
#
|
25
|
-
def initialize(component)
|
26
|
-
@component
|
29
|
+
def initialize(component, options = {})
|
30
|
+
@component = component
|
31
|
+
@component_options = options
|
27
32
|
|
28
33
|
super() # keep parenthesis, parent method doesn't take arguments.
|
29
34
|
end
|
@@ -58,7 +63,7 @@ module Opener
|
|
58
63
|
raise ArgumentError, 'No mapper has been set in the `:mapper` option'
|
59
64
|
end
|
60
65
|
|
61
|
-
return option(:mapper).new(component)
|
66
|
+
return option(:mapper).new(component, component_options)
|
62
67
|
end
|
63
68
|
|
64
69
|
##
|
@@ -7,8 +7,11 @@ module Opener
|
|
7
7
|
# @!attribute [r] component
|
8
8
|
# @return [Class]
|
9
9
|
#
|
10
|
+
# @!attribute [r] component_options
|
11
|
+
# @return [Hash]
|
12
|
+
#
|
10
13
|
class Mapper < Oni::Mapper
|
11
|
-
attr_reader :component
|
14
|
+
attr_reader :component, :component_options
|
12
15
|
|
13
16
|
##
|
14
17
|
# The directory containing JSON schema files.
|
@@ -26,9 +29,11 @@ module Opener
|
|
26
29
|
|
27
30
|
##
|
28
31
|
# @param [Class] component
|
32
|
+
# @param [Hash] component_options
|
29
33
|
#
|
30
|
-
def initialize(component)
|
31
|
-
@component
|
34
|
+
def initialize(component, component_options = {})
|
35
|
+
@component = component
|
36
|
+
@component_options = component_options
|
32
37
|
end
|
33
38
|
|
34
39
|
##
|
@@ -40,7 +45,7 @@ module Opener
|
|
40
45
|
|
41
46
|
validate_input!(decoded)
|
42
47
|
|
43
|
-
return Configuration.new(component, decoded)
|
48
|
+
return Configuration.new(component, component_options, decoded)
|
44
49
|
end
|
45
50
|
|
46
51
|
##
|
@@ -42,8 +42,7 @@ module Opener
|
|
42
42
|
add_newrelic_attributes
|
43
43
|
|
44
44
|
input = downloader.download(config.input_url)
|
45
|
-
|
46
|
-
output = instance.run(input)
|
45
|
+
output = config.component_instance.run(input)
|
47
46
|
object = uploader.upload(config.identifier, output, config.metadata)
|
48
47
|
|
49
48
|
Syslog.info(
|