Class: GooglePubsubEnhancer
- Inherits:
-
Object
- Object
- GooglePubsubEnhancer
show all
- Defined in:
- lib/google_pubsub_enhancer.rb,
lib/google_pubsub_enhancer/version.rb
Defined Under Namespace
Modules: Constants, Spec
Classes: Middleware
Constant Summary
collapse
- VERSION =
"0.5.0"
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(logger: Logger.new(STDOUT), &block) ⇒ GooglePubsubEnhancer
Returns a new instance of GooglePubsubEnhancer.
26
27
28
29
|
# File 'lib/google_pubsub_enhancer.rb', line 26
def initialize(logger: Logger.new(STDOUT),&block)
@logger = logger
@stack = ::Middleware::Builder.new(&block).__send__(:to_app)
end
|
Class Method Details
.name_by(type, name) ⇒ Object
13
14
15
16
|
# File 'lib/google_pubsub_enhancer.rb', line 13
def name_by(type, name)
raise unless %w(topics subscriptions).include?(type)
"projects/#{pubsub_config['project_id']}/#{type}/#{name}"
end
|
.pubsub_config ⇒ Object
18
19
20
21
22
23
|
# File 'lib/google_pubsub_enhancer.rb', line 18
def pubsub_config
key = ::Google::Cloud::Pubsub::Credentials::JSON_ENV_VARS.find { |n| !ENV[n].nil? }
@pubsub_config ||= JSON.parse(ENV[key])
rescue => ex
raise Exception, 'Environment not setted properly'
end
|
Instance Method Details
#run(subscription_short_name, opts = {}) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/google_pubsub_enhancer.rb', line 31
def run(subscription_short_name, opts={})
configurated_options = configurate_options(opts)
subscription = create_subscription(subscription_short_name)
work(subscription, configurated_options)
rescue => ex
@logger.error "Retry: #{ex} "
retry
end
|