opener-daemons 2.0.2 → 2.1.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
2
  SHA1:
3
- metadata.gz: 03b7be7e62ee26df448d1eab7ef16b439fc68200
4
- data.tar.gz: ecee4827ada3b9b70d5411628b2eebf48a955e2e
3
+ metadata.gz: cd43444725d72e2076b674d5c1a4ae46b7c2a514
4
+ data.tar.gz: a315f9989260c5c36efbe29d412120abcef97802
5
5
  SHA512:
6
- metadata.gz: fcf4c032d995b86df844c3fed445c56292e4a7139f74c153aa968f018a0dcfc1a240b500c74f516b10f16fc538de4cb6f15bc7326154d0055ac2a7d474dbc5e3
7
- data.tar.gz: c4f90bac71ab8ca51dbc92eaac7c107c226f005754932dfa96006faa520072bbee58a58a7474f5d5b1dbb0e57594f517648e7f9dffe5a6d3526ef3f4b636af31
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
- If the component takes extra arguments, such as a resource path, these should be
62
- set in the `initialize` method of the component using the actual environment
63
- variables.
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, :metadata
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 = 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 = 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 = 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
  ##
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  module Daemons
3
- VERSION = '2.0.2'
3
+ VERSION = '2.1.0'
4
4
  end # Daemons
5
5
  end # Opener
@@ -42,8 +42,7 @@ module Opener
42
42
  add_newrelic_attributes
43
43
 
44
44
  input = downloader.download(config.input_url)
45
- instance = config.component.new
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(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-daemons
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilco van Duinkerken