fix: shutdown on error
This commit is contained in:
		
							parent
							
								
									7725019ed7
								
							
						
					
					
						commit
						b1cc2af8d8
					
				
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@ -1,6 +1,6 @@
 | 
				
			|||||||
module go.sour.is/pkg
 | 
					module go.sour.is/pkg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.20
 | 
					go 1.21
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/99designs/gqlgen v0.17.34
 | 
						github.com/99designs/gqlgen v0.17.34
 | 
				
			||||||
 | 
				
			|||||||
@ -71,7 +71,7 @@ func (w wrapSpan) AddEvent(name string, options ...trace.EventOption) {
 | 
				
			|||||||
		args[2*i+1] = a.Value
 | 
							args[2*i+1] = a.Value
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	slog.Info(name, args...)
 | 
						slog.Debug(name, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (w wrapSpan) RecordError(err error, options ...trace.EventOption) {
 | 
					func (w wrapSpan) RecordError(err error, options ...trace.EventOption) {
 | 
				
			||||||
@ -142,7 +142,7 @@ func initTracing(ctx context.Context, name string) (context.Context, func() erro
 | 
				
			|||||||
		return ctx, nil
 | 
							return ctx, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	exporterAddr := env.Default("EV_TRACE_ENDPOINT", "")
 | 
						exporterAddr := env.Default("TRACE_ENDPOINT", "")
 | 
				
			||||||
	if exporterAddr == "" {
 | 
						if exporterAddr == "" {
 | 
				
			||||||
		return ctx, nil
 | 
							return ctx, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -93,7 +93,7 @@ func (s *Harness) Run(ctx context.Context, appName, version string) error {
 | 
				
			|||||||
		span.End()
 | 
							span.End()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	g, _ := errgroup.WithContext(ctx)
 | 
						g, ctx := errgroup.WithContext(ctx)
 | 
				
			||||||
	g.Go(func() error {
 | 
						g.Go(func() error {
 | 
				
			||||||
		<-ctx.Done()
 | 
							<-ctx.Done()
 | 
				
			||||||
		// shutdown jobs
 | 
							// shutdown jobs
 | 
				
			||||||
@ -111,7 +111,10 @@ func (s *Harness) Run(ctx context.Context, appName, version string) error {
 | 
				
			|||||||
	close(s.onRunning)
 | 
						close(s.onRunning)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := g.Wait()
 | 
						err := g.Wait()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Printf("Shutdown due to error: %s", err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user