Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Auddia/pubsub-tie
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a5661a6d9266aca2ee26db5defcddb96c6bf56a8
Choose a base ref
..
head repository: Auddia/pubsub-tie
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d40eaab9a9c1333e0b0fd05585a6d48d94058f48
Choose a head ref
Showing with 22 additions and 3 deletions.
  1. +2 −2 Gemfile.lock
  2. +4 −0 lib/pubsub_tie.rb
  3. +15 −0 lib/pubsub_tie/publisher.rb
  4. +1 −1 lib/pubsub_tie/version.rb
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
pubsub_tie (0.0.1)
pubsub_tie (0.0.2)
google-cloud-pubsub (~> 1.6)

GEM
@@ -93,4 +93,4 @@ DEPENDENCIES
rspec (~> 3.0)

BUNDLED WITH
1.17.2
1.17.3
4 changes: 4 additions & 0 deletions lib/pubsub_tie.rb
Original file line number Diff line number Diff line change
@@ -39,6 +39,10 @@ def configure_events
def publish(topic, data, resource: nil)
Publisher.publish(topic, data, resource)
end

def batch(topic, data, resource: nil)
Publisher.batch(topic, data, resource)
end
end

require 'pubsub_tie/railtie' if defined? Rails::Railtie
15 changes: 15 additions & 0 deletions lib/pubsub_tie/publisher.rb
Original file line number Diff line number Diff line change
@@ -29,6 +29,21 @@ def publish(topic_sym, data, resource)
end
end

def batch(topic_sym, messages, resource)
topic = @pubsub.
topic(Events.name topic_sym)
messages.each do |data|
topic.publish_async(message(validate_data(topic_sym, data), resource),
publish_time: Time.now.utc) do |result|
unless result.succeeded?
Rails.logger.error(
"Failed to publish #{data} to #{topic_sym} on #{data} due to #{result.error}")
end
end
end
topic.async_publisher.stop.wait!
end

private
def message(data, resource)
# TODO: embed resource in message
2 changes: 1 addition & 1 deletion lib/pubsub_tie/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PubSubTie
VERSION = "0.0.1"
VERSION = "0.0.2"
end