internal/queue: increase task timeout

HTTP tasks (but not AppEngine tasks) have a default timeout of 10
minutes. Extend that to the maximum of 30 minutes.

Change-Id: I75efc0523ff83471a0a2a8d453e1284483feefe1
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258197
Reviewed-by: Julie Qiu <julie@golang.org>
Trust: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Jonathan Amsterdam 2020-09-29 06:14:34 -04:00
Родитель 8962bff2e3
Коммит e91ba8014e
3 изменённых файлов: 13 добавлений и 1 удалений

1
go.mod
Просмотреть файл

@ -20,6 +20,7 @@ require (
github.com/gogo/protobuf v1.3.0 // indirect
github.com/golang-migrate/migrate/v4 v4.6.2
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
github.com/golang/protobuf v1.4.2
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/google/go-cmp v0.5.2
github.com/google/go-replayers/httpreplay v0.1.0

Просмотреть файл

@ -14,6 +14,7 @@ import (
"time"
cloudtasks "cloud.google.com/go/cloudtasks/apiv2"
"github.com/golang/protobuf/ptypes"
"golang.org/x/pkgsite/internal/config"
"golang.org/x/pkgsite/internal/derrors"
"golang.org/x/pkgsite/internal/experiment"
@ -139,10 +140,17 @@ func (q *GCP) ScheduleFetch(ctx context.Context, modulePath, version, suffix str
return enqueued, nil
}
// Maximum timeout for HTTP tasks.
// See https://cloud.google.com/tasks/docs/creating-http-target-tasks.
const maxCloudTasksTimeout = 30 * time.Minute
func (q *GCP) newTaskRequest(modulePath, version, suffix string, taskIDChangeInterval time.Duration) *taskspb.CreateTaskRequest {
taskID := newTaskID(modulePath, version, time.Now(), taskIDChangeInterval)
relativeURI := fmt.Sprintf("/fetch/%s/@v/%s", modulePath, version)
task := &taskspb.Task{Name: fmt.Sprintf("%s/tasks/%s", q.queueName, taskID)}
task := &taskspb.Task{
Name: fmt.Sprintf("%s/tasks/%s", q.queueName, taskID),
DispatchDeadline: ptypes.DurationProto(maxCloudTasksTimeout),
}
if q.queueService != "" {
task.MessageType = &taskspb.Task_AppEngineHttpRequest{
AppEngineHttpRequest: &taskspb.AppEngineHttpRequest{

Просмотреть файл

@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/google/go-cmp/cmp"
"golang.org/x/pkgsite/internal/config"
taskspb "google.golang.org/genproto/googleapis/cloud/tasks/v2"
@ -50,6 +51,7 @@ func TestNewTaskRequest(t *testing.T) {
&taskspb.CreateTaskRequest{
Parent: "projects/Project/locations/us-central1/queues/queueID",
Task: &taskspb.Task{
DispatchDeadline: ptypes.DurationProto(maxCloudTasksTimeout),
MessageType: &taskspb.Task_AppEngineHttpRequest{
AppEngineHttpRequest: &taskspb.AppEngineHttpRequest{
HttpMethod: taskspb.HttpMethod_POST,
@ -74,6 +76,7 @@ func TestNewTaskRequest(t *testing.T) {
&taskspb.CreateTaskRequest{
Parent: "projects/Project/locations/us-central1/queues/queueID",
Task: &taskspb.Task{
DispatchDeadline: ptypes.DurationProto(maxCloudTasksTimeout),
MessageType: &taskspb.Task_HttpRequest{
HttpRequest: &taskspb.HttpRequest{
HttpMethod: taskspb.HttpMethod_POST,