Skip to content

Commit

Permalink
Verison 1.0.0
Browse files Browse the repository at this point in the history
* Fixes a rare panic.
* Try to log panics to logfile, if a logfile is configured.
  • Loading branch information
comstud committed Jul 11, 2024
1 parent 695e73d commit 7e0f564
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions bin/fletchling/fletchling.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/UnownHash/Fletchling/filters"
"github.com/UnownHash/Fletchling/pyroscope"
"github.com/UnownHash/Fletchling/stats_collector"
"github.com/UnownHash/Fletchling/util"
"github.com/UnownHash/Fletchling/version"
"github.com/UnownHash/Fletchling/webhook_sender"

Expand Down Expand Up @@ -88,6 +89,10 @@ func main() {
if err != nil {
log.Fatal(err)
}

util.SetPanicLogger(logger)
defer util.HandlePanic()

logger.Infof("STARTUP: Version %s. Config loaded.", version.APP_VERSION)

statsCollector := stats_collector.GetStatsCollector(cfg)
Expand All @@ -109,6 +114,7 @@ func main() {

wg.Add(1)
go func() {
defer util.HandlePanic()
defer wg.Done()
defer cancelFn()

Expand Down Expand Up @@ -218,6 +224,7 @@ func main() {

wg.Add(1)
go func() {
defer util.HandlePanic()
defer wg.Done()
defer cancelFn()

Expand All @@ -243,6 +250,7 @@ func main() {

wg.Add(1)
go func() {
defer util.HandlePanic()
defer wg.Done()
// shut down everything else if this bails early
defer cancelFn()
Expand All @@ -257,6 +265,7 @@ func main() {
} else {
wg.Add(1)
go func() {
defer util.HandlePanic()
defer wg.Done()
defer cancelFn()

Expand Down
2 changes: 2 additions & 0 deletions db_store/nests.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sync"
"time"

"github.com/UnownHash/Fletchling/util"
_ "github.com/go-sql-driver/mysql"
"github.com/golang-migrate/migrate/v4"
migrate_mysql "github.com/golang-migrate/migrate/v4/database/mysql"
Expand Down Expand Up @@ -364,6 +365,7 @@ func (st *NestsDBStore) IterateNestsConcurrently(ctx context.Context, opts Itera
for _ = range opts.Concurrency {
wg.Add(1)
go func() {
defer util.HandlePanic()

Check failure on line 368 in db_store/nests.go

View workflow job for this annotation

GitHub Actions / test

undefined: util.HandlePanic

Check failure on line 368 in db_store/nests.go

View workflow job for this annotation

GitHub Actions / test

undefined: util.HandlePanic
defer wg.Done()
for {
select {
Expand Down
3 changes: 3 additions & 0 deletions httpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/UnownHash/Fletchling/filters"
"github.com/UnownHash/Fletchling/processor"
"github.com/UnownHash/Fletchling/stats_collector"
"github.com/UnownHash/Fletchling/util"
)

func init() {
Expand All @@ -39,6 +40,8 @@ func (srv *HTTPServer) Run(ctx context.Context, address string, shutdownWaitTime
doneCh := make(chan error, 1)

go func() {
defer util.HandlePanic()

var err error
defer func() {
doneCh <- err
Expand Down
3 changes: 3 additions & 0 deletions httpserver/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"gopkg.in/guregu/null.v4"

"github.com/UnownHash/Fletchling/processor/models"
"github.com/UnownHash/Fletchling/util"
)

type decoderFn func([]byte, *WebhookMessage) error
Expand Down Expand Up @@ -91,6 +92,8 @@ func (wh *PokemonWebhook) EncounterIdAsInt() (uint64, error) {
}

func (srv *HTTPServer) processMessages(msgs []WebhookMessage) {
defer util.HandlePanic()

var numProcessed uint64

now := time.Now()
Expand Down
3 changes: 3 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/UnownHash/Fletchling/db_store"
"github.com/UnownHash/Fletchling/processor/models"
"github.com/UnownHash/Fletchling/util"
)

// NestProcessor is the pokemon nest processor.
Expand Down Expand Up @@ -257,6 +258,8 @@ func (np *NestProcessor) GetStatsSnapshot() *FrozenStatsCollection {
}

func (np *NestProcessor) ProcessStatsCollection(statsCollection *FrozenStatsCollection) {
defer util.HandlePanic()

np.LogConfiguration("PROCESSOR: time period processing starting with configuration: ", np.nestMatcher.Len())
defer np.logger.Infof("PROCESSOR: time period processing ending")

Expand Down
2 changes: 1 addition & 1 deletion processor/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (counts *CountsByPokemon) subtract(logger *logrus.Logger, other *CountsByPo
*other,
)
}
counts.ByPokemon = nil
counts.ByPokemon = make(map[models.PokemonKey]uint64)
return true
}

Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package version

const (
APP_VERSION = "0.99.10"
APP_VERSION = "1.0.0"
)
4 changes: 4 additions & 0 deletions webhook_sender/poracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/UnownHash/Fletchling/areas"
"github.com/UnownHash/Fletchling/geo"
"github.com/UnownHash/Fletchling/processor/models"
"github.com/UnownHash/Fletchling/util"
)

type NestWebhookMessage struct {
Expand Down Expand Up @@ -166,12 +167,15 @@ func (sender *PoracleSender) AddNestWebhook(nest *models.Nest, ni *models.Nestin
// Flush will send the collected webhooks. This is meant to be used after
// the web server has been shut down and before the program exits.
func (sender *PoracleSender) Flush() {
defer util.HandlePanic()

var wg sync.WaitGroup

messages := sender.popNestMessagesFromQueue()
for _, destination := range sender.destinations {
wg.Add(1)
go func(destination *webhookDestination) {
defer util.HandlePanic()
defer wg.Done()
destination.sendMessages(messages)
}(destination)
Expand Down

0 comments on commit 7e0f564

Please sign in to comment.