@@ -89,6 +89,34 @@ def delete_subscription(project, subscription_name):
89
89
print ('Subscription deleted: {}' .format (subscription_path ))
90
90
91
91
92
+ def update_subscription (project , subscription_name , ack_deadline_seconds ):
93
+ """
94
+ Updates an existing Pub/Sub subscription's ackDeadlineSeconds
95
+ from 10 seconds (default). Note that certain properties of a
96
+ subscription, such as its topic, are not modifiable.
97
+ """
98
+ subscriber = pubsub_v1 .SubscriberClient ()
99
+ subscription_path = subscriber .subscription_path (
100
+ project , subscription_name )
101
+
102
+ subscription = pubsub_v1 .types .Subscription (
103
+ name = subscription_path ,
104
+ ack_deadline_seconds = ack_deadline_seconds )
105
+
106
+ update_mask = {
107
+ 'paths' : {
108
+ 'ack_deadline_seconds' ,
109
+ }
110
+ }
111
+
112
+ subscriber .update_subscription (subscription , update_mask )
113
+ result = subscriber .get_subscription (subscription_path )
114
+
115
+ print ('Subscription updated: {}' .format (subscription_path ))
116
+ print ('New ack_deadline_seconds value is: {}' .format (
117
+ result .ack_deadline_seconds ))
118
+
119
+
92
120
def receive_messages (project , subscription_name ):
93
121
"""Receives messages from a pull subscription."""
94
122
subscriber = pubsub_v1 .SubscriberClient ()
@@ -183,6 +211,11 @@ def callback(message):
183
211
'delete' , help = delete_subscription .__doc__ )
184
212
delete_parser .add_argument ('subscription_name' )
185
213
214
+ update_parser = subparsers .add_parser (
215
+ 'update' , help = update_subscription .__doc__ )
216
+ update_parser .add_argument ('subscription_name' )
217
+ update_parser .add_argument ('ack_deadline_seconds' , type = int )
218
+
186
219
receive_parser = subparsers .add_parser (
187
220
'receive' , help = receive_messages .__doc__ )
188
221
receive_parser .add_argument ('subscription_name' )
@@ -214,6 +247,9 @@ def callback(message):
214
247
elif args .command == 'delete' :
215
248
delete_subscription (
216
249
args .project , args .subscription_name )
250
+ elif args .command == 'update' :
251
+ update_subscription (
252
+ args .project , args .subscription_name , args .ack_deadline_seconds )
217
253
elif args .command == 'receive' :
218
254
receive_messages (args .project , args .subscription_name )
219
255
elif args .command == 'receive-flow-control' :
0 commit comments