77 "time"
88
99 cloudtasks "cloud.google.com/go/cloudtasks/apiv2"
10+ "cloud.google.com/go/cloudtasks/apiv2/cloudtaskspb"
1011 "github.com/NdoleStudio/httpsms/pkg/telemetry"
1112 "github.com/palantir/stacktrace"
12- taskspb "google.golang.org/genproto/googleapis/cloud/tasks/v2"
1313 "google.golang.org/protobuf/types/known/timestamppb"
1414)
1515
@@ -48,13 +48,11 @@ func (queue *googlePushQueue) Enqueue(ctx context.Context, task *PushQueueTask,
4848 }
4949
5050 // Build the Task payload.
51- // https://godoc.org/google.golang.org/genproto/googleapis/cloud/tasks/v2#CreateTaskRequest
52- req := & taskspb.CreateTaskRequest {
51+ req := & cloudtaskspb.CreateTaskRequest {
5352 Parent : queue .queueConfig .Name ,
54- Task : & taskspb.Task {
55- // https://godoc.org/google.golang.org/genproto/googleapis/cloud/tasks/v2#HttpRequest
56- MessageType : & taskspb.Task_HttpRequest {
57- HttpRequest : & taskspb.HttpRequest {
53+ Task : & cloudtaskspb.Task {
54+ MessageType : & cloudtaskspb.Task_HttpRequest {
55+ HttpRequest : & cloudtaskspb.HttpRequest {
5856 Headers : headers ,
5957 HttpMethod : queue .httpMethodToProtoHTTPMethod (task .Method ),
6058 Url : task .URL ,
@@ -67,9 +65,12 @@ func (queue *googlePushQueue) Enqueue(ctx context.Context, task *PushQueueTask,
6765 // Add a payload message if one is present.
6866 req .Task .GetHttpRequest ().Body = task .Body
6967
70- queueTask , err := queue .client .CreateTask (ctx , req )
68+ requestCtx , cancel := context .WithTimeout (ctx , time .Second )
69+ defer cancel ()
70+
71+ queueTask , err := queue .client .CreateTask (requestCtx , req )
7172 if err != nil {
72- msg := fmt .Sprintf ("cannot schedule task %s to URL: %s " , string (task .Body ), task .URL )
73+ msg := fmt .Sprintf ("cannot schedule task [%s] to URL [%s] " , string (task .Body ), task .URL )
7374 return queueID , queue .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
7475 }
7576
@@ -83,15 +84,15 @@ func (queue *googlePushQueue) Enqueue(ctx context.Context, task *PushQueueTask,
8384 return queueTask .Name , nil
8485}
8586
86- func (queue * googlePushQueue ) httpMethodToProtoHTTPMethod (httpMethod string ) taskspb .HttpMethod {
87- method , ok := map [string ]taskspb .HttpMethod {
88- http .MethodGet : taskspb .HttpMethod_GET ,
89- http .MethodPost : taskspb .HttpMethod_POST ,
90- http .MethodPut : taskspb .HttpMethod_PUT ,
87+ func (queue * googlePushQueue ) httpMethodToProtoHTTPMethod (httpMethod string ) cloudtaskspb .HttpMethod {
88+ method , ok := map [string ]cloudtaskspb .HttpMethod {
89+ http .MethodGet : cloudtaskspb .HttpMethod_GET ,
90+ http .MethodPost : cloudtaskspb .HttpMethod_POST ,
91+ http .MethodPut : cloudtaskspb .HttpMethod_PUT ,
9192 }[httpMethod ]
9293
9394 if ! ok {
94- return taskspb .HttpMethod_POST
95+ return cloudtaskspb .HttpMethod_POST
9596 }
9697
9798 return method
0 commit comments