cloudtasks

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package cloudtasks is the Cloud Tasks emulation.

A task is deferred HTTP work: it names a URL, a schedule time and a body, and the queue dispatches it when that time arrives, retrying on failure. The dispatch runs on the injected clock, so a test advances time to fire a task due in an hour rather than waiting one — which is the thing that cannot be done against real Cloud Tasks.

Index

Constants

View Source
const MaxBodyBytes = 4 << 20

MaxBodyBytes caps a JSON request body. A task payload is small; an unbounded read is a way to exhaust the process, and the port is shared.

Variables

This section is empty.

Functions

This section is empty.

Types

type REST

type REST struct {
	// contains filtered or unexported fields
}

REST serves the Cloud Tasks JSON API so `gcloud tasks` works. The Go client speaks gRPC; gcloud speaks REST, over the same service.

func NewREST

func NewREST(s *Service) *REST

NewREST wires the routes gcloud drives.

func (*REST) Matches

func (a *REST) Matches(method, escapedPath string) bool

Matches reports whether a route here claims the request; /v2/ is shared with Cloud Functions.

func (*REST) ServeHTTP

func (a *REST) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Service

type Service struct {
	cloudtaskspb.UnimplementedCloudTasksServer
	// contains filtered or unexported fields
}

Service holds queues and their tasks, and dispatches due tasks.

func New

func New(kv store.Store, clk clock.Clock) *Service

New wires a service. A nil doer uses the real HTTP client.

func (*Service) CreateQueue

func (*Service) CreateTask

CreateTask stores a task and arms its dispatch. A task with no schedule time is due now.

func (*Service) DeleteQueue

func (s *Service) DeleteQueue(ctx context.Context, req *cloudtaskspb.DeleteQueueRequest) (*emptypb.Empty, error)

func (*Service) DeleteTask

func (s *Service) DeleteTask(ctx context.Context, req *cloudtaskspb.DeleteTaskRequest) (*emptypb.Empty, error)

func (*Service) GetQueue

func (*Service) GetTask

func (*Service) PauseQueue

func (*Service) PurgeQueue

func (*Service) ResumeQueue

func (*Service) RunTask

RunTask dispatches a task now, ahead of its schedule. It is how an operator forces a task without waiting for its time.

func (*Service) Started

func (s *Service) Started() uint64

Started counts due-now dispatches ever launched, so a drain can tell whether a pass triggered new work and needs another round.

func (*Service) Sync

func (s *Service) Sync()

Sync waits for every due-now dispatch to finish, including arming any retry it scheduled. Timer-driven dispatches run synchronously inside the clock's Advance and need no waiting; only the immediate goroutine path does.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL