workqueue
This module provisions a regionalized workqueue abstraction over Google Cloud
Storage that implements a Kubernetes-like workqueue abstraction for processing
work with concurrency control, in an otherwise stateless fashion (using Google
Cloud Run).
Keys are put into the queue and processed from the queue using a symmetrical
GRPC service definition under ./pkg/workqueue/workqueue.proto
. This module
takes the name of a service implementing this proto service, and exposes the
name of a service into which work can be enqueued.
module "workqueue" {
source = "chainguard-dev/common/infra//modules/workqueue"
project_id = var.project_id
name = "${var.name}-workqueue"
regions = var.regions
// The number of keys to process concurrently.
concurrent-work = 10
// The name of a service that implements the workqueue GRPC service above.
reconciler-service = {
name = "foo"
}
notification_channels = var.notification_channels
}
// Authorize the bar service to queue keys in our workqueue.
module "bar-queues-keys" {
for_each = var.regions
source = "chainguard-dev/common/infra//modules/authorize-private-service"
project_id = var.project_id
region = each.key
name = module.workqueue.receiver.name
service-account = google_service_account.fanout.email
}
// Stand up the bar service in each of our regions.
module "bar-service" {
source = "chainguard-dev/common/infra//modules/regional-go-service"
...
regional-env = [{
name = "WORKQUEUE_SERVICE"
value = { for k, v in module.bar-queues-keys : k => v.uri }
}]
...
}
Then the "bar" service initializes a client for the workqueue GRPC service
pointing at WORKQUEUE_SERVICE
with Cloud Run authentication (see the
workqueue.NewWorkqueueClient
helper), and queues keys, e.g.
// Set up the client
client, err := workqueue.NewWorkqueueClient(ctx, os.Getenv("WORKQUEUE_SERVICE"))
if err != nil {
log.Panicf("failed to create client: %v", err)
}
defer client.Close()
// Process a key!
if _, err := client.Process(ctx, &workqueue.ProcessRequest{
Key: key,
}); err != nil {
log.Panicf("failed to process key: %v", err)
}
Requirements
No requirements.
Providers
Modules
Resources
Name |
Description |
Type |
Default |
Required |
concurrent-work |
The amount of concurrent work to dispatch at a given time. |
number |
n/a |
yes |
name |
n/a |
string |
n/a |
yes |
notification_channels |
List of notification channels to alert. |
list(string) |
n/a |
yes |
project_id |
n/a |
string |
n/a |
yes |
reconciler-service |
The name of the reconciler service that the workqueue will dispatch work to. |
object({ name = string }) |
n/a |
yes |
regions |
A map from region names to a network and subnetwork. A service will be created in each region configured to egress the specified traffic via the specified subnetwork. |
map(object({ network = string subnet = string })) |
n/a |
yes |
Outputs