Skip to content
Snippets Groups Projects
Verified Commit ba7b214f authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

fix: correct issues with running http and asynq in parallel


Signed-off-by: default avatarJanne Mareike Koschinski <janne@kuschku.de>
parent 01b84573
No related branches found
No related tags found
No related merge requests found
Pipeline #2809 passed
......@@ -53,14 +53,15 @@ func main() {
Handler: metricsMux,
}
go func() {
runner := shared.Runner{}
runner.RunParallel(func() {
if err := metrics.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Printf("error in metrics server: %s", err.Error())
}
log.Printf("metrics shut down, shutting down asynq as well")
srv.Shutdown()
}()
go func() {
})
runner.RunParallel(func() {
if err := srv.Run(mux); err != nil {
log.Printf("error in asynq server: %s", err.Error())
}
......@@ -68,5 +69,6 @@ func main() {
if err := metrics.Shutdown(context.Background()); err != nil {
log.Printf("error shutting down metrics server: %s", err.Error())
}
}()
})
runner.Wait()
}
package shared
import "sync"
type Runner struct {
wg sync.WaitGroup
}
func (runner *Runner) RunParallel(closure func()) {
runner.wg.Add(1)
go func() {
closure()
runner.wg.Done()
}()
}
func (runner *Runner) Wait() {
runner.wg.Wait()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment