Switched to backlite for task queues.

This commit is contained in:
mikestefanello 2024-07-24 21:04:32 -04:00
parent 062d1f70be
commit f54d9f8b37
11 changed files with 91 additions and 372 deletions

View file

@ -9,6 +9,7 @@ import (
"net/http"
"os"
"os/signal"
"sync"
"time"
"github.com/mikestefanello/pagoda/pkg/handlers"
@ -60,18 +61,32 @@ func main() {
tasks.Register(c)
// Start the task runner to execute queued tasks
ctx, cancel := context.WithCancel(context.Background())
go c.Tasks.StartRunner(ctx)
c.Tasks.Start(context.Background())
// Wait for interrupt signal to gracefully shut down the server with a timeout of 10 seconds.
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
signal.Notify(quit, os.Kill)
<-quit
cancel()
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
// Shutdown both the task runner and web server
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := c.Web.Shutdown(ctx); err != nil {
log.Fatal(err)
}
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
defer wg.Done()
c.Tasks.Stop(ctx)
}()
go func() {
defer wg.Done()
if err := c.Web.Shutdown(ctx); err != nil {
log.Fatal(err)
}
}()
wg.Wait()
}