Categorygithub.com/imjasonh/delay
modulepackage
0.0.0-20240410024906-3d77a37b517b
Repository: https://github.com/imjasonh/delay.git
Documentation: pkg.go.dev

# README

delay

Image of relay race

NOTE: This is not an official Google project. It's an experimental derivative of the google.golang.org/appengine/delay package. Where that package is intended for App Engine applications, this package is intended to be used with Cloud Run.


delay is a package that attempts to bring the simplicity of google.golang.org/appengine/delay to Cloud Run apps, to make it simpler to enqueue work to be handled later using Cloud Tasks.

Prerequisites

You must create the Task Queue yourself, which requires creating an App Engine application. That application and region must match the region where the Cloud Run service is deployed.

Usage

First, register your handler function. This must be done at init-time.

import "github.com/imjasonh/delay/"

var laterFunc = delay.Func(myFunc)

You can also use a function literal:

var laterFunc = delay.Func(func(ctx context.Context, some, args string) error {
	...
})

Before calling the function you should also initialize the package:

func init() {
	delay.Init()
}

Then, to call the function, invoke its Call method.

err := laterFunc.Call(ctx, req, queueName, "arg1", "arg2", "arg3")

Each time the function is invoked, a Cloud Task will be enqueued which will be handled by the specified handler function.

You can also schedule invocation for a time in the future with laterFunc.Delay, specifying a duration to wait. This instructs the Cloud Tasks queue to invoke the function at a time in the future.

# Packages

No description provided by the author

# Functions

Func declares a new Function.
No description provided by the author
Request returns the special task-queue HTTP request headers for the current task queue handler.

# Structs

Function represents a function that may have a delayed invocation.
Meta contains the special HTTP request headers available to push task HTTP request handlers.