From bf84f75be444344888799a227ef44cdd35a78cb0 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Wed, 2 Nov 2022 01:06:08 -0400 Subject: [PATCH] apparently workers run all jobs --- internal/cmd/worker.go | 22 +++++++--------------- render.yaml | 24 +++++------------------- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/internal/cmd/worker.go b/internal/cmd/worker.go index 6e11750..f57c392 100644 --- a/internal/cmd/worker.go +++ b/internal/cmd/worker.go @@ -24,25 +24,20 @@ var ( func WorkerCmd(ctx context.Context) *cobra.Command { var consumers int - var queueID string cmd := &cobra.Command{ Use: "worker", Args: cobra.ExactArgs(0), Short: "Work through job queues.", RunE: func(cmd *cobra.Command, args []string) error { - if queueID == "" { - return fmt.Errorf("need a queue to work on") - } - runtime.SetBlockProfileRate(1) runtime.SetMutexProfileFraction(1) - svc := fmt.Sprintf("worker: %s", queueID) + svc := fmt.Sprintf("worker") logger := cmdutil.NewLogger(svc) defer func() { _ = logger.Sync() }() - tag := fmt.Sprintf("worker:%s", queueID) + tag := fmt.Sprintf("worker") statsd, err := cmdutil.NewStatsdClient(tag) if err != nil { return err @@ -63,21 +58,18 @@ func WorkerCmd(ctx context.Context) *cobra.Command { } defer redis.Close() - workerFn, ok := queues[queueID] - if !ok { - return fmt.Errorf("queue does not exist: %s", queueID) - } - worker := workerFn(ctx, logger, statsd, db, redis, consumers) - mgr := faktoryworker.NewManager() mgr.Concurrency = consumers - mgr.Register(queueID, worker.Process) + for queue, workerFn := range queues { + worker := workerFn(ctx, logger, statsd, db, redis, consumers) + mgr.Register(queue, worker.Process) + } + return mgr.RunWithContext(ctx) }, } cmd.Flags().IntVar(&consumers, "consumers", runtime.NumCPU()*64, "The consumers to run") - cmd.Flags().StringVar(&queueID, "queue", "", "The queue to work on") return cmd } diff --git a/render.yaml b/render.yaml index 3178d1a..0bff8a4 100644 --- a/render.yaml +++ b/render.yaml @@ -105,7 +105,7 @@ services: maxInstances: 30 targetCPUPercent: 80 buildCommand: go install github.com/bugsnag/panic-monitor@latest && go build ./cmd/apollo - startCommand: panic-monitor ./apollo worker --queue notifications --consumers 256 + startCommand: panic-monitor ./apollo worker --queue NotificationCheckJob --consumers 256 # Stuck Notifications Checker - type: worker @@ -123,7 +123,7 @@ services: maxInstances: 10 targetCPUPercent: 80 buildCommand: go install github.com/bugsnag/panic-monitor@latest && go build ./cmd/apollo - startCommand: panic-monitor ./apollo worker --queue stuck-notifications --consumers 64 + startCommand: panic-monitor ./apollo worker --queue StuckNotificationsJob --consumers 64 # Scheduler - type: worker @@ -137,20 +137,6 @@ services: buildCommand: go install github.com/bugsnag/panic-monitor@latest && go build ./cmd/apollo startCommand: panic-monitor ./apollo scheduler -# User Watcher -- type: worker - name: worker.watcher.users - env: go - plan: starter - envVars: - - fromGroup: env-settings - - key: BUGSNAG_APP_TYPE - value: worker - - key: BUGSNAG_METADATA_QUEUE - value: users - buildCommand: go install github.com/bugsnag/panic-monitor@latest && go build ./cmd/apollo - startCommand: panic-monitor ./apollo worker --queue users - # Subreddit Watcher - type: worker name: worker.watcher.subreddits @@ -167,7 +153,7 @@ services: maxInstances: 10 targetCPUPercent: 80 buildCommand: go install github.com/bugsnag/panic-monitor@latest && go build ./cmd/apollo - startCommand: panic-monitor ./apollo worker --queue subreddits + startCommand: panic-monitor ./apollo worker --queue SubredditWatcherJob # Trending Posts Watcher - type: worker @@ -185,7 +171,7 @@ services: maxInstances: 10 targetCPUPercent: 80 buildCommand: go install github.com/bugsnag/panic-monitor@latest && go build ./cmd/apollo - startCommand: panic-monitor ./apollo worker --queue trending + startCommand: panic-monitor ./apollo worker --queue SubredditTrendingJob # Live Activities - type: worker @@ -203,7 +189,7 @@ services: maxInstances: 10 targetCPUPercent: 80 buildCommand: go install github.com/bugsnag/panic-monitor@latest && go build ./cmd/apollo - startCommand: panic-monitor ./apollo worker --queue live-activities + startCommand: panic-monitor ./apollo worker --queue LiveActivityJob envVarGroups: # Environment