https://github.com/imjasonh/delay
Go package to make Cloud Tasks simpler for Cloud Run applications
https://github.com/imjasonh/delay
async cloud-run cloud-tasks golang
Last synced: 5 months ago
JSON representation
Go package to make Cloud Tasks simpler for Cloud Run applications
- Host: GitHub
- URL: https://github.com/imjasonh/delay
- Owner: imjasonh
- License: apache-2.0
- Created: 2020-12-01T11:53:30.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-10T02:49:13.000Z (almost 2 years ago)
- Last Synced: 2025-03-25T10:12:01.245Z (10 months ago)
- Topics: async, cloud-run, cloud-tasks, golang
- Language: Go
- Homepage:
- Size: 74.2 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `delay`
**NOTE:** This is not an official Google project. It's an experimental
derivative of the
[`google.golang.org/appengine/delay`](https://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.