Documentation
¶
Overview ¶
Package delay provides a task queue abstraction for background job execution. This is a standalone implementation that replaces the google.golang.org/appengine/delay package.
Index ¶
Constants ¶
const (
// Path is the HTTP path for invocations (maintained for compatibility)
Path = "/_/queue/delay"
)
Variables ¶
Functions ¶
func Drain ¶ added in v1.49.26
Drain stops queued tasks from waiting any longer and waits for the ones already running to return, or for ctx to expire — whichever comes first. It returns ctx.Err() when the wait ran out of time, meaning tasks are still in flight and the datastore is not yet safe to close.
Call it during shutdown after the HTTP listener has drained, so nothing new is being queued, and before closing the database. Both callers do exactly that: App.Shutdown and the test context's Close.
Draining is not permanent. Once the wait is over the queue re-arms, so a process that drains for a checkpoint keeps working and a test binary running several contexts in sequence gets a clean queue for each.
Types ¶
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
Function wraps a delayed function with queue configuration
func Func ¶
Func declares a new Function. The second argument must be a function with a first argument of type context.Context. This function must be called at program initialization time. That means it must be called in a global variable declaration or from an init function. This restriction is necessary because the instance that delays a function call may not be the one that executes it. Only the code executed at program initialization time is guaranteed to have been run by an instance before it receives a request.
func (*Function) After ¶ added in v1.49.26
After returns a copy of this Function whose calls wait d before running.
It exists so a caller that wants to re-queue work with a backoff can say so through the queue instead of writing its own `go func` around a Sleep. A hand-rolled goroutine is untracked: it registers its task only after waking, which is too late for a Drain that has already counted the parent out.
func (*Function) Call ¶
Call invokes a delayed function asynchronously using goroutines. The function is executed in a background goroutine after any configured delay.
type RequestHeaders ¶
RequestHeaders contains metadata from the task queue request. This replaces taskqueue.RequestHeaders from appengine.
func ParseRequestHeaders ¶
func ParseRequestHeaders(h http.Header) *RequestHeaders
ParseRequestHeaders extracts task queue headers from an HTTP request. This is a compatibility function for HTTP-based task invocation.