Files
gis/internal/cli/worker.go
Bakhtiyar Issakhmetov ad3c9fbdcd feat(landscape): HTTP API, worker consumer, wiring, docs
Adds the /landscape routes (slots, slot upload, runs, run detail, results),
mounts them in the router, wires the landscape repository, job publisher,
godal raster IO and Compute into the composition root, and registers the
gis-landscape-runner consumer in the worker.

Also fixes the Dockerfile so the image actually runs: godal's cgo needs g++,
and the runtime base must match the builder's Alpine release or libgdal's
soname does not resolve.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-05 14:11:57 +05:00

54 lines
1.2 KiB
Go

package cli
import (
"context"
"errors"
"gis/internal/app"
"gis/internal/messaging/rabbitmq"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
)
var publishExample bool
var workerCmd = &cobra.Command{
Use: "worker",
Short: "Run the RabbitMQ consumers (dataset processing, landscape runs + example)",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := signalContext()
defer cancel()
application, err := app.New(ctx)
if err != nil {
return err
}
defer application.Close()
if publishExample {
if err := rabbitmq.PublishExample(ctx, application.Publisher()); err != nil {
return err
}
application.Log.Info("published example message")
}
// Run every consumer concurrently; cancel all if one fails.
g, gctx := errgroup.WithContext(ctx)
for _, c := range application.Consumers() {
c := c
g.Go(func() error { return c.Run(gctx) })
}
// Graceful shutdown (context cancelled) is not an error.
if err := g.Wait(); err != nil && !errors.Is(err, context.Canceled) {
return err
}
return nil
},
}
func init() {
workerCmd.Flags().BoolVar(&publishExample, "publish-example", false, "publish one example message before consuming")
}