Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RunCmd = &cobra.Command{ Use: "worker", Short: "", Long: ``, Run: func(cmd *cobra.Command, args []string) { defer log.Flush() defer func() { if r := recover(); r != nil { err, ok := r.(error) if !ok { err = fmt.Errorf("unknown error: %v", r) } log.Err(err).Panic("unknown error") } }() config.EnvPrefix = "STARTER" cfg := config.New("app.yml") err := initialize(cfg) if err != nil { log.Fatalf("main: initialize failed: %v", err) return } tp, err := cfg.TracerProvider("worker") ctx, cancel := context.WithCancel(context.Background()) defer cancel() defer func(ctx context.Context) { ctx, cancel = context.WithTimeout(ctx, time.Second*5) defer cancel() if err := tp.Shutdown(ctx); err != nil { log.Err(err).Panic("tp shutdown failed") } }(ctx) tr := otel.Tracer("") bridgeTracer, _ := opentracing.NewTracerPair(tr) c, err := client.NewClient(client.Options{ HostPort: cfg.Temporal.Address, ContextPropagators: []workflow.ContextPropagator{ starterWorkflow.NewContextPropagator(), }, Tracer: bridgeTracer, }) if err != nil { log.Err(err).Fatal("Unable to create client") } defer c.Close() w := worker.New(c, "default", worker.Options{ WorkerStopTimeout: 10, }) w.RegisterWorkflow(starterWorkflow.PublishEventWorkflow) w.RegisterActivity(starterWorkflow.WithdrawActivity) w.RegisterActivity(starterWorkflow.PublishEventActivity) err = w.Run(worker.InterruptCh()) if err != nil { log.Err(err).Fatalf("Unable to start worker") } log.Info("worker has stopped") }, }
RunCmd 是 worker service 的進入口
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.