lib/google_pubsub_enhancer/middleware/publisher.rb in google-pubsub-enhancer-0.5.3 vs lib/google_pubsub_enhancer/middleware/publisher.rb in google-pubsub-enhancer-0.5.4

- old
+ new

@@ -8,18 +8,20 @@ @logger = opts[:logger] || Logger.new(STDOUT) @google_cloud_pubsub ||= Google::Cloud::Pubsub.new end def call(env) - @logger.debug("#{env[@messages_key].length} messages published") - @google_cloud_pubsub.publish(@full_topic_name) do |publisher| - [*env[@messages_key]].each do |m| - publisher.publish(m) + begin + @logger.debug("#{env[@messages_key].length} messages published") + @google_cloud_pubsub.publish(@full_topic_name) do |publisher| + [*env[@messages_key]].each do |m| + publisher.publish(m) + end end + rescue => ex + @logger.error("Retry publisher: #{ex}") + retry end - rescue => ex - @logger.error("Retry publisher: #{ex}") - retry @app.call(env) end end