11package moderation
22
33import (
4+ "context"
45 "fmt"
56 "log/slog"
7+ "time"
8+
9+ "go.temporal.io/sdk/client"
10+ "go.temporal.io/sdk/log"
11+ "opencsg.com/csghub-server/builder/instrumentation"
12+ "opencsg.com/csghub-server/builder/temporal"
613
714 "github.com/spf13/cobra"
815 "opencsg.com/csghub-server/api/httpbase"
916 "opencsg.com/csghub-server/builder/store/database"
1017 "opencsg.com/csghub-server/common/config"
1118 "opencsg.com/csghub-server/moderation/checker"
1219 "opencsg.com/csghub-server/moderation/router"
13- "opencsg.com/csghub-server/moderation/workflow"
1420)
1521
1622var cmdLaunch = & cobra.Command {
@@ -23,6 +29,10 @@ var cmdLaunch = &cobra.Command{
2329 return err
2430 }
2531 slog .Debug ("config" , slog .Any ("data" , cfg ))
32+ stopOtel , err := instrumentation .SetupOTelSDK (context .Background (), cfg , instrumentation .Moderation )
33+ if err != nil {
34+ panic (err )
35+ }
2636 // Check APIToken length
2737 if len (cfg .APIToken ) < 128 {
2838 return fmt .Errorf ("API token length is less than 128, please check" )
@@ -36,11 +46,16 @@ var cmdLaunch = &cobra.Command{
3646 return fmt .Errorf ("database initialization failed: %w" , err )
3747 }
3848 checker .Init (cfg )
39-
40- //init async moderation process
41- err = workflow .StartWorker (cfg )
49+ slog .Info ("starting temporal client" )
50+ temporalClient , err := temporal .NewClient (client.Options {
51+ HostPort : cfg .WorkFLow .Endpoint ,
52+ Logger : log .NewStructuredLogger (slog .Default ()),
53+ ConnectionOptions : client.ConnectionOptions {
54+ GetSystemInfoTimeout : time .Duration (cfg .Temporal .GetSystemInfoTimeout ) * time .Second ,
55+ },
56+ }, instrumentation .Moderation )
4257 if err != nil {
43- return fmt .Errorf ("failed to start workflow worker, %w" , err )
58+ return fmt .Errorf ("unable to create temporal client, error: %w" , err )
4459 }
4560
4661 r , err := router .NewRouter (cfg )
@@ -56,8 +71,8 @@ var cmdLaunch = &cobra.Command{
5671 )
5772 server .Run ()
5873
59- workflow . StopWorker ( )
60-
74+ _ = stopOtel ( context . Background () )
75+ temporalClient . Close ()
6176 return nil
6277 },
6378}
0 commit comments