Skip to content

Commit

Permalink
added --queryTimeout flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Feb 23, 2023
1 parent 6ab2fa9 commit e529fe7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/base/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
Expand Down Expand Up @@ -52,6 +53,14 @@ func main() {
"fallback the request to index.html on missing static path (eg. when pretty urls are used with SPA)",
)

var queryTimeout int
app.RootCmd.PersistentFlags().IntVar(
&queryTimeout,
"queryTimeout",
30,
"the default SELECT queries timeout in seconds",
)

app.RootCmd.ParseFlags(os.Args[1:])

// ---------------------------------------------------------------
Expand All @@ -70,6 +79,11 @@ func main() {
Dir: migrationsDir,
})

app.OnAfterBootstrap().Add(func(e *core.BootstrapEvent) error {
app.Dao().ModelQueryTimeout = time.Duration(queryTimeout) * time.Second
return nil
})

app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
// serves static files from the provided public dir (if exists)
e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS(publicDir), indexFallback))
Expand Down

0 comments on commit e529fe7

Please sign in to comment.