cloudenvoy 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 788d59dcdb276ba209ea7502f1d03765ab0beac646089ac5891ea67967a96a25
4
- data.tar.gz: 819add5f2b7d7b3b37fc6f1f32d008af05fddd1409d585e0a88c7249f0427f57
3
+ metadata.gz: 504b503a71e3417dc060ca78ab1653e670b77a87a094394d231e1c8d6bace2f9
4
+ data.tar.gz: fc905028b47de294dc1a42c7c6ea6edbf3148db8c2e9f94c3b656f2f480fd317
5
5
  SHA512:
6
- metadata.gz: 3df6bb839c332feea426ec26ac09f46c951f8997159a53d32ce5ac3a11549648842f747ae1b2a0e962f399d8d12a11e6a64501d72134c0347485d39ec07d0ca8
7
- data.tar.gz: cd320825e2b8c842e2746c5b7acbfbb82751f743c9bae38a4e997f411a3aa44b6d1e658bf8c8a7afba108ecc7fcc3a5cca4bd2c4b9711a9bfeadd1d88e512c31
6
+ metadata.gz: 7f91e316422710774f1298c9e8f675c89c79e2e6b1043903b8beacf5c7929696b7d3131f25aeda9f3cd54f0b1f81c65291b9ec92dfa4acb66ef03c837e5c6d89
7
+ data.tar.gz: 7d6cfe241d6477428c40c40fd28975c8e27752a4d485ba2a40a865d8d60f426770118f88e376ee6bc8750277cebff8f3e5dc14f59463c44ccfcfd4918c763109
@@ -1,4 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.2.0](https://github.com/keypup-io/cloudenvoy/tree/v0.2.0) (2020-09-22)
4
+
5
+ [Full Changelog](https://github.com/keypup-io/cloudenvoy/compare/v0.1.0...v0.2.0)
6
+
7
+ **Improvements:**
8
+ - Subscriptions: support creation options such as `retained_acked` and `deadline`
9
+
3
10
  ## [v0.1.0](https://github.com/keypup-io/cloudenvoy/tree/v0.1.0) (2020-09-16)
4
11
  Initial release
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudenvoy (0.1.0)
4
+ cloudenvoy (0.2.0)
5
5
  activesupport
6
6
  google-cloud-pubsub (~> 2.0)
7
7
  jwt
data/README.md CHANGED
@@ -357,7 +357,19 @@ class UserSubscriber
357
357
  include Cloudenvoy::Subscriber
358
358
 
359
359
  # Subscribers can subscribe to multiple topics
360
- cloudenvoy_options topics: ['system-users']
360
+ #
361
+ # You can subscribe to multiple topics:
362
+ # > cloudenvoy_options topics: ['system-users', 'events']
363
+ #
364
+ # You can specify subscription options for each topic
365
+ # by passing a hash (target: v0.2.0)
366
+ #
367
+ # > cloudenvoy_options topics: ['system-users', { name: 'events', retain_acked: true }]
368
+ #
369
+ # See the Pub/Sub documentation of the list of available subscription options:
370
+ # https://googleapis.dev/ruby/google-cloud-pubsub/latest/Google/Cloud/PubSub/Topic.html#subscribe-instance_method
371
+ #
372
+ cloudenvoy_options topic: 'system-users'
361
373
 
362
374
  # Create the user locally if it does not exist already
363
375
  #
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cloudenvoy (0.1.0)
4
+ cloudenvoy (0.2.0)
5
5
  activesupport
6
6
  google-cloud-pubsub (~> 2.0)
7
7
  jwt
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cloudenvoy (0.1.0)
4
+ cloudenvoy (0.2.0)
5
5
  activesupport
6
6
  google-cloud-pubsub (~> 2.0)
7
7
  jwt
@@ -68,21 +68,42 @@ module Cloudenvoy
68
68
  #
69
69
  # @param [String] topic The name of the topic
70
70
  # @param [String] name The name of the subscription
71
+ # @param [Hash] opts The subscription configuration options
72
+ # @option opts [Integer] :deadline The maximum number of seconds after a subscriber receives a message
73
+ # before the subscriber should acknowledge the message.
74
+ # @option opts [Boolean] :retain_acked Indicates whether to retain acknowledged messages. If true,
75
+ # then messages are not expunged from the subscription's backlog, even if they are acknowledged,
76
+ # until they fall out of the retention window. Default is false.
77
+ # @option opts [<Type>] :retention How long to retain unacknowledged messages in the subscription's
78
+ # backlog, from the moment a message is published. If retain_acked is true, then this also configures
79
+ # the retention of acknowledged messages, and thus configures how far back in time a Subscription#seek
80
+ # can be done. Cannot be more than 604,800 seconds (7 days) or less than 600 seconds (10 minutes).
81
+ # Default is 604,800 seconds (7 days).
82
+ # @option opts [String] :filter An expression written in the Cloud Pub/Sub filter language.
83
+ # If non-empty, then only Message instances whose attributes field matches the filter are delivered
84
+ # on this subscription. If empty, then no messages are filtered out. Optional.
71
85
  #
72
86
  # @return [Cloudenvoy::Subscription] The upserted subscription.
73
87
  #
74
- def upsert_subscription(topic, name)
75
- ps_sub = begin
76
- # Retrieve the topic
77
- ps_topic = backend.topic(topic, skip_lookup: true)
88
+ def upsert_subscription(topic, name, opts = {})
89
+ sub_config = opts.to_h.merge(endpoint: webhook_url)
78
90
 
79
- # Attempt to create the subscription
80
- ps_topic.subscribe(name, endpoint: webhook_url)
81
- rescue Google::Cloud::AlreadyExistsError
82
- # Update endpoint on subscription
83
- # Topic is not updated as it is name-dependent
84
- backend.subscription(name).tap { |e| e.endpoint = webhook_url }
85
- end
91
+ ps_sub =
92
+ begin
93
+ # Retrieve the topic
94
+ ps_topic = backend.topic(topic, skip_lookup: true)
95
+
96
+ # Attempt to create the subscription
97
+ ps_topic.subscribe(name, sub_config)
98
+ rescue Google::Cloud::AlreadyExistsError
99
+ # Update endpoint on subscription
100
+ # Topic is not updated as it is name-dependent
101
+ backend.subscription(name).tap do |e|
102
+ sub_config.each do |k, v|
103
+ e.send("#{k}=", v)
104
+ end
105
+ end
106
+ end
86
107
 
87
108
  # Return formatted subscription
88
109
  Subscription.new(name: ps_sub.name, original: ps_sub)
@@ -66,10 +66,11 @@ module Cloudenvoy
66
66
  #
67
67
  # @param [String] topic The name of the topic
68
68
  # @param [String] name The name of the subscription
69
+ # @param [Hash] opts The subscription configuration options
69
70
  #
70
71
  # @return [Cloudenvoy::Subscription] The upserted subscription.
71
72
  #
72
- def upsert_subscription(_topic, name)
73
+ def upsert_subscription(_topic, name, _opts)
73
74
  Subscription.new(name: name)
74
75
  end
75
76
 
@@ -41,11 +41,25 @@ module Cloudenvoy
41
41
  #
42
42
  # @param [String] topic The name of the topic
43
43
  # @param [String] name The name of the subscription
44
+ # @param [Hash] opts The subscription configuration options
45
+ # @option opts [Integer] :deadline The maximum number of seconds after a subscriber receives a message
46
+ # before the subscriber should acknowledge the message.
47
+ # @option opts [Boolean] :retain_acked Indicates whether to retain acknowledged messages. If true,
48
+ # then messages are not expunged from the subscription's backlog, even if they are acknowledged,
49
+ # until they fall out of the retention window. Default is false.
50
+ # @option opts [<Type>] :retention How long to retain unacknowledged messages in the subscription's
51
+ # backlog, from the moment a message is published. If retain_acked is true, then this also configures
52
+ # the retention of acknowledged messages, and thus configures how far back in time a Subscription#seek
53
+ # can be done. Cannot be more than 604,800 seconds (7 days) or less than 600 seconds (10 minutes).
54
+ # Default is 604,800 seconds (7 days).
55
+ # @option opts [String] :filter An expression written in the Cloud Pub/Sub filter language.
56
+ # If non-empty, then only Message instances whose attributes field matches the filter are delivered
57
+ # on this subscription. If empty, then no messages are filtered out. Optional.
44
58
  #
45
59
  # @return [Cloudenvoy::Subscription] The upserted subscription.
46
60
  #
47
- def self.upsert_subscription(topic, name)
48
- backend.upsert_subscription(topic, name)
61
+ def self.upsert_subscription(topic, name, opts = {})
62
+ backend.upsert_subscription(topic, name, opts)
49
63
  end
50
64
 
51
65
  #
@@ -98,10 +98,12 @@ module Cloudenvoy
98
98
  # Return the list of topics this subscriber listens
99
99
  # to.
100
100
  #
101
- # @return [Array<String>] The list of subscribed topics.
101
+ # @return [Array<Hash>] The list of subscribed topics.
102
102
  #
103
103
  def topics
104
- cloudenvoy_options_hash[:topics] || []
104
+ @topics ||= (Array(cloudenvoy_options_hash[:topic]) + Array(cloudenvoy_options_hash[:topics])).map do |t|
105
+ t.is_a?(String) ? { name: t } : t
106
+ end
105
107
  end
106
108
 
107
109
  #
@@ -125,7 +127,9 @@ module Cloudenvoy
125
127
  #
126
128
  def setup
127
129
  topics.map do |t|
128
- PubSubClient.upsert_subscription(t, subscription_name(t))
130
+ relative_name = t[:name] || t['name']
131
+ sub_opts = t.reject { |k, _| k.to_sym == :name }
132
+ PubSubClient.upsert_subscription(t, subscription_name(relative_name), sub_opts)
129
133
  end
130
134
  end
131
135
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudenvoy
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudenvoy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Lachaume
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-16 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport