2022-04-26 17:57:01 +00:00
|
|
|
package shutdown
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-05-06 15:03:15 +00:00
|
|
|
"os"
|
2022-04-26 17:57:01 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/vulcanize/ipld-ethcl-indexer/pkg/beaconclient"
|
|
|
|
"github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql"
|
|
|
|
"github.com/vulcanize/ipld-ethcl-indexer/pkg/gracefulshutdown"
|
|
|
|
"github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Shutdown all the internal services for the application.
|
2022-05-06 15:03:15 +00:00
|
|
|
func ShutdownServices(ctx context.Context, notifierCh chan os.Signal, waitTime time.Duration, DB sql.Database, BC *beaconclient.BeaconClient) error {
|
|
|
|
successCh, errCh := gracefulshutdown.Shutdown(ctx, notifierCh, waitTime, map[string]gracefulshutdown.Operation{
|
|
|
|
// Combining DB shutdown with BC because BC needs DB open to cleanly shutdown.
|
2022-04-26 17:57:01 +00:00
|
|
|
"beaconClient": func(ctx context.Context) error {
|
2022-05-06 15:03:15 +00:00
|
|
|
defer DB.Close()
|
2022-04-26 17:57:01 +00:00
|
|
|
err := BC.StopHeadTracking()
|
|
|
|
if err != nil {
|
|
|
|
loghelper.LogError(err).Error("Unable to trigger shutdown of head tracking")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
},
|
|
|
|
})
|
2022-04-27 14:28:42 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case _ = <-successCh:
|
2022-04-28 18:50:29 +00:00
|
|
|
return nil
|
2022-04-27 14:28:42 +00:00
|
|
|
case err := <-errCh:
|
2022-04-28 18:50:29 +00:00
|
|
|
return err
|
2022-04-27 14:28:42 +00:00
|
|
|
}
|
2022-04-26 17:57:01 +00:00
|
|
|
}
|