lib/google_pubsub_enhancer.rb in google-pubsub-enhancer-0.1.3 vs lib/google_pubsub_enhancer.rb in google-pubsub-enhancer-0.1.4
- old
+ new
@@ -1,11 +1,13 @@
require 'json'
require 'middleware'
require 'google/cloud/pubsub'
class GooglePubsubEnhancer
- require 'google_pubsub_enhancer/publisher'
+
+ require_relative 'google_pubsub_enhancer/middleware'
+
class << self
def name_by(type, name)
raise unless %w(topics subscriptions).include?(type)
"projects/#{pubsub_config['project_id']}/#{type}/#{name}"
end
@@ -15,11 +17,11 @@
@pubsub_config ||= JSON.parse(ENV[key])
end
end
def initialize(&block)
- @stack = Middleware::Builder.new(&block)
+ @stack = ::Middleware::Builder.new(&block)
end
def run(subscription_short_name, opts={})
configurated_options = configurate_options(opts)
subscription = create_subscription(subscription_short_name)
@@ -33,10 +35,10 @@
def work(subscription, opts)
while received_messages = subscription.pull
break if opts[:shutdown].call || received_messages == nil
next if received_messages.empty?
@stack.call({received_messages: received_messages})
- subscription.acknowledge(received_messages)
+ subscription.acknowledge(received_messages)
end
end
def create_subscription(subscription_short_name)
Google::Cloud::Pubsub.new.subscription(self.class.name_by('subscriptions', subscription_short_name))