https://github.com/chainguard-dev/go-workqueue
https://github.com/chainguard-dev/go-workqueue
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/chainguard-dev/go-workqueue
- Owner: chainguard-dev
- Created: 2024-08-19T03:25:12.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-09-04T19:13:05.000Z (9 months ago)
- Last Synced: 2024-09-06T02:48:56.410Z (9 months ago)
- Language: Go
- Size: 146 KB
- Stars: 3
- Watchers: 1
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-workqueue
This is a Go library that can be used to queue and process work with a number of
properties reminiscient of Kubernetes Controller's workqueue, but that
support being backed by durable storage (e.g. GCS, S3).Given a `workqueue.Interface` new keys can be added to the queue with
deduplication by simply calling `Queue(ctx, key)`. For example:```go
func foo(ctx context.Context, wq workqueue.Interface) error {
if err := wq.Queue(ctx, "foo"); err != nil {
return err
}
if err := wq.Queue(ctx, "bar"); err != nil {
return err
}
if err := wq.Queue(ctx, "baz"); err != nil {
return err
}
return nil
}
```Up to `N` items of concurrent work may be processed from the workqueue by
invoking the `Handle` method in the
`github.com/chainguard-dev/go-workqueue/dispatcher` package. For example:```go
if err := dispatcher.Handle(ctx, wq, N, func(ctx context.Context, key string) error {
// Process the key!
clog.InfoContextf(ctx, "Got key: %s", key)
return nil
}); err != nil {
return err
}
```