Skip to content

Commit

Permalink
worker: switch to using the rivets controller package
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel committed Apr 4, 2024
1 parent 91ed505 commit 9606566
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 1,156 deletions.
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ lint: gen-mock
test: lint
go test -timeout 1m -v -covermode=atomic ./...

## Generate mocks
gen-mock:
go get go.uber.org/mock@v0.4.0
go install go.uber.org/mock/mockgen@v0.4.0
go generate ./...
go mod tidy

## build-osx
build-osx:
ifeq (${GO_VERSION}, 0)
Expand Down
4 changes: 2 additions & 2 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func asGraph(s *sw.StateMachineJSON) *dot.Graph {
return g
}

func taskStateMachine() {
func conditionStateMachine() {
g := dot.NewGraph(dot.Directed)

pending := g.Node(string(model.StatePending))
Expand Down Expand Up @@ -103,7 +103,7 @@ func outofbandActionStatemachine() {

func exportStatemachine() {
if exportFlagSet.taskSM {
taskStateMachine()
conditionStateMachine()

return
}
Expand Down
42 changes: 27 additions & 15 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/metal-toolbox/flasher/internal/model"
"github.com/metal-toolbox/flasher/internal/store"
"github.com/metal-toolbox/flasher/internal/worker"
"github.com/metal-toolbox/rivets/events/controller"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"go.hollow.sh/toolbox/events"

// nolint:gosec // profiling endpoint listens on localhost.
_ "net/http/pprof"
Expand Down Expand Up @@ -70,36 +70,48 @@ func runWorker(ctx context.Context) {
cancelFunc()
}()

inv, err := initInventory(ctx, flasher.Config, flasher.Logger)
repository, err := initStore(ctx, flasher.Config, flasher.Logger)
if err != nil {
flasher.Logger.Fatal(err)
}

stream, err := events.NewStream(*flasher.Config.NatsOptions)
if facilityCode == "" {
flasher.Logger.Fatal("--facility-code parameter required")
}

natsURL, natsCreds, connectTimeout, err := flasher.NatsParams()
if err != nil {
flasher.Logger.Fatal(err)
}

if useStatusKV && facilityCode == "" {
flasher.Logger.Fatal("--use-kv flag requires a --facility-code parameter")
nc := controller.NewNatsController(
model.AppName,
facilityCode,
"firmwareInstall",
natsURL,
natsCreds,
"firmwareInstall",
controller.WithConcurrency(10),
controller.WithKVReplicas(1),
controller.WithLogger(flasher.Logger),
controller.WithConnectionTimeout(connectTimeout),
)

if err := nc.Connect(ctx); err != nil {
flasher.Logger.Fatal(err)
}

w := worker.New(
facilityCode,
worker.Run(
ctx,
dryrun,
useStatusKV,
faultInjection,
flasher.Config.Concurrency,
replicas,
stream,
inv,
repository,
nc,
flasher.Logger,
)

w.Run(ctx)
}

func initInventory(ctx context.Context, config *app.Configuration, logger *logrus.Logger) (store.Repository, error) {
func initStore(ctx context.Context, config *app.Configuration, logger *logrus.Logger) (store.Repository, error) {
switch {
// from CLI flags
case strings.HasSuffix(storeKind, ".yml"), strings.HasSuffix(storeKind, ".yaml"):
Expand Down
39 changes: 20 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/metal-toolbox/flasher

go 1.20
go 1.22

require (
github.com/banzaicloud/logrus-runtime-formatter v0.0.0-20190729070250-5ae5475bae5e
Expand All @@ -17,25 +17,25 @@ require (
github.com/jeremywohl/flatten v1.0.1
github.com/jinzhu/copier v0.4.0
github.com/jpillora/backoff v1.0.0
github.com/metal-toolbox/conditionorc v1.0.4
github.com/metal-toolbox/rivets v0.2.2
github.com/metal-toolbox/rivets v1.0.2-0.20240321173737-71ffdb3bf742
github.com/mitchellh/mapstructure v1.5.0
github.com/nats-io/nats-server/v2 v2.10.7
github.com/nats-io/nats-server/v2 v2.10.11
github.com/nats-io/nats.go v1.33.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
go.hollow.sh/serverservice v0.16.2
go.hollow.sh/toolbox v0.6.2
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
go.uber.org/goleak v1.3.0
go.uber.org/mock v0.4.0
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
golang.org/x/net v0.21.0
golang.org/x/net v0.22.0
golang.org/x/oauth2 v0.17.0
)

Expand All @@ -45,14 +45,14 @@ require (
github.com/VictorLowther/simplexml v0.0.0-20180716164440-0bff93621230 // indirect
github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.11.1 // indirect
github.com/bytedance/sonic v1.11.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/cockroachdb/cockroach-go/v2 v2.3.6 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 // indirect
github.com/ericlagergren/decimal v0.0.0-20240305081647-93d586550569 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/friendsofgo/errors v0.9.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -64,7 +64,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.18.0 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -78,13 +78,13 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.1 // indirect
github.com/jackc/pgconn v1.14.3 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgtype v1.14.2 // indirect
github.com/jackc/pgx/v4 v4.18.1 // indirect
github.com/jackc/pgx/v4 v4.18.2 // indirect
github.com/jacobweinstock/iamt v0.0.0-20230502042727-d7cdbe67d9ef // indirect
github.com/jacobweinstock/registrar v0.4.7 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
Expand All @@ -98,15 +98,15 @@ require (
github.com/minio/highwayhash v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nats-io/jwt/v2 v2.5.3 // indirect
github.com/nats-io/jwt/v2 v2.5.5 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/pquerna/cachecontrol v0.2.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/common v0.49.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -116,6 +116,7 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stmcginnis/gofish v0.15.1-0.20231121142100-22a60a77be91 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
Expand All @@ -136,15 +137,15 @@ require (
go.uber.org/zap v1.27.0 // indirect
gocloud.dev v0.36.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.20.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.167.0 // indirect
google.golang.org/api v0.168.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading

0 comments on commit 9606566

Please sign in to comment.