Skip to content

Commit

Permalink
Add log when a goroutine panics
Browse files Browse the repository at this point in the history
  • Loading branch information
FluxCapacitor2 committed Aug 9, 2024
1 parent 98f9a97 commit d0b101d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/easysearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/fluxcapacitor2/easysearch/app/crawler"
"github.com/fluxcapacitor2/easysearch/app/database"
"github.com/fluxcapacitor2/easysearch/app/server"
"github.com/go-co-op/gocron/v2"
"github.com/google/uuid"
)

// TODO: look into dependency injection instead of passing the DB and config into every function call
Expand All @@ -22,6 +24,10 @@ func main() {
panic(fmt.Sprintf("Invalid configuration: %v", err))
}

gocron.AfterJobRunsWithPanic(func(jobID uuid.UUID, jobName string, recoverData interface{}) {
fmt.Printf("Panic in job %v (ID: %v): %+v\n", jobName, jobID, recoverData)
})

// Set up a database connection using the specified driver
var db database.Database

Expand Down

0 comments on commit d0b101d

Please sign in to comment.