1
0
Fork 0
mirror of https://github.com/imjasonh/delay synced 2026-07-07 00:33:26 +00:00
No description
Find a file
Jason Hall 3d77a37b51
modernize
Signed-off-by: Jason Hall <jason@chainguard.dev>
2024-04-09 22:49:06 -04:00
example modernize 2024-04-09 22:49:06 -04:00
.gitignore modernize 2024-04-09 22:49:06 -04:00
delay.go modernize 2024-04-09 22:49:06 -04:00
delay_test.go modernize 2024-04-09 22:49:06 -04:00
DEVELOPMENT.md add DEVELOPMENT.md and move example 2020-12-01 22:06:46 -05:00
go.mod modernize 2024-04-09 22:49:06 -04:00
go.sum modernize 2024-04-09 22:49:06 -04:00
LICENSE add LICENSE 2020-12-01 22:04:02 -05:00
README.md modernize 2024-04-09 22:49:06 -04:00
relay.jpg update README 2020-12-01 09:58:03 -05:00

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.