MCPcopy
hub / github.com/harness/harness / run

Method run

cli/operations/server/server.go:44–181  ·  view source on GitHub ↗
(*kingpin.ParseContext)

Source from the content-addressed store, hash-verified

42}
43
44func (c *command) run(*kingpin.ParseContext) error {
45 // Create context that listens for the interrupt signal from the OS.
46 ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
47 defer stop()
48
49 // load environment variables from file.
50 // no error handling needed when file is not present
51 _ = godotenv.Load(c.envfile)
52
53 // create the system configuration store by loading
54 // data from the environment.
55 config, err := LoadConfig()
56 if err != nil {
57 return fmt.Errorf("encountered an error while loading configuration: %w", err)
58 }
59
60 // configure the log level
61 SetupLogger(config)
62
63 // configure profiler
64 SetupProfiler(config)
65
66 // add logger to context
67 log := log.Logger.With().Logger()
68 ctx = log.WithContext(ctx)
69
70 // initialize system
71 system, err := c.initializer(ctx, config)
72 if err != nil {
73 return fmt.Errorf("encountered an error while wiring the system: %w", err)
74 }
75
76 // bootstrap the system
77 err = system.bootstrap(ctx)
78 if err != nil {
79 return fmt.Errorf("encountered an error while bootstrapping the system: %w", err)
80 }
81
82 // gCtx is canceled if any of the following occurs:
83 // - any go routine launched with g encounters an error
84 // - ctx is canceled
85 g, gCtx := errgroup.WithContext(ctx)
86
87 g.Go(func() error {
88 // initialize metric collector
89 if system.services.MetricCollector != nil {
90 if err := system.services.MetricCollector.Register(gCtx); err != nil {
91 log.Error().Err(err).Msg("failed to register metric collector")
92 return err
93 }
94 }
95
96 if system.services.RepoSizeCalculator != nil {
97 if err := system.services.RepoSizeCalculator.Register(gCtx); err != nil {
98 log.Error().Err(err).Msg("failed to register repo size calculator")
99 return err
100 }
101 }

Callers

nothing calls this directly

Calls 15

WithWrappedZerologFunction · 0.92
LoadConfigFunction · 0.85
SetupLoggerFunction · 0.85
SetupProfilerFunction · 0.85
MsgMethod · 0.80
PopulateMethod · 0.80
ShutdownMethod · 0.80
WaitJobsDoneMethod · 0.80
WaitMethod · 0.80
RegisterMethod · 0.65
ErrMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected