Start task runner before web server.

This commit is contained in:
mikestefanello 2025-02-12 22:01:46 -05:00
parent f8192d3ad6
commit 4e5c5127e8

View file

@ -5,6 +5,7 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/mikestefanello/pagoda/pkg/tasks"
"log"
"net/http"
"os"
@ -14,7 +15,6 @@ import (
"github.com/mikestefanello/pagoda/pkg/handlers"
"github.com/mikestefanello/pagoda/pkg/services"
"github.com/mikestefanello/pagoda/pkg/tasks"
)
func main() {
@ -31,6 +31,12 @@ func main() {
log.Fatalf("failed to build the router: %v", err)
}
// Register all task queues
tasks.Register(c)
// Start the task runner to execute queued tasks
c.Tasks.Start(context.Background())
// Start the server
go func() {
srv := http.Server{
@ -57,12 +63,6 @@ func main() {
}
}()
// Register all task queues
tasks.Register(c)
// Start the task runner to execute queued tasks
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)