PubSub
Ability to set ExpirationPolicy on pubsub SubscriptionConfig{} object. Currently, ExpirationPolicy cannot be set on the subscription. This feature exists in the API and Google Cloud Console when creating a subscription.
here it is in the protobuf:
https://github.com/google/go-genproto/blob/master/googleapis/pubsub/v1/pubsub.pb.go#L953
@sduskis @kir-titievsky @kamalaboulhosn
@jadekler, it would indeed be awesome to have expiration policy and oidc_token in the pub/sub subscription CRUD.
For some status updates, we are almost finished with this feature:
This is a good addition, however, I am not sure how I would use this feature to set the expiration policy to "never expire," a feature which is available through the GCP UI. Did I miss something in the documentation?
Great question @lc-caigwatkin! So the GCP UI and gcloud cli use a sentinel value of "never" and we are going to mimick the same by providing a NeverExpire constant in a CL coming up shortly.
Thus code to do this will look like this:
package main
import (
"context"
"log"
"time"
"cloud.google.com/go/pubsub"
)
func main() {
ctx := context.Background()
client, err := pubsub.NewClient(ctx, "odeke-sandbox")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
defer client.Close()
topic, _ := client.CreateTopic(ctx, "issue-1361-t")
// Create the new subscription
subName := "sub-1361"
_, _ = client.CreateSubscription(ctx, subName, pubsub.SubscriptionConfig{
Topic: topic,
AckDeadline: 30 * time.Second,
ExpirationPolicy: 25 * time.Hour,
})
gotSub := client.Subscription(subName)
cfg, err := gotSub.Config(ctx)
if err != nil {
log.Fatalf("Failed to retrieve the config: %v", err)
}
log.Printf("Config: %+v\n", cfg)
<-time.After(1 * time.Minute)
// Now update it.
sCfg := pubsub.SubscriptionConfigToUpdate{
ExpirationPolicy: pubsub.NeverExpire,
}
updated, _ := gotSub.Update(ctx, sCfg)
log.Printf("Updated: %+v\n", updated)
}
and you'll be able to verify on the UI that ExpirationPolicy is set to NEVER expire.
Thanks @odeke-em
From looking at your example, is it best practice to first create a subscription that is not set to never expire before updating it as such? Or would simply creating it with pubsub.NeverExpire be just as good?
That example is just to show you that you can update it. But from the get-go you'll be able to set it to pubsub.NeverExpire so during creation too.
Excellent! Thanks for your explanation
For posterity: https://code-review.googlesource.com/c/gocloud/+/41211
I believe this issue can now be closed and all CLs have been merged.
/cc @hongalex
Most helpful comment
This is a good addition, however, I am not sure how I would use this feature to set the expiration policy to "never expire," a feature which is available through the GCP UI. Did I miss something in the documentation?