1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-01-08 09:14:37 +02:00

added --queryTimeout flag

This commit is contained in:
Gani Georgiev 2023-02-23 18:59:23 +02:00
parent 6ab2fa9489
commit e529fe7e2a

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"github.com/pocketbase/pocketbase" "github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis" "github.com/pocketbase/pocketbase/apis"
@ -52,6 +53,14 @@ func main() {
"fallback the request to index.html on missing static path (eg. when pretty urls are used with SPA)", "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:]) app.RootCmd.ParseFlags(os.Args[1:])
// --------------------------------------------------------------- // ---------------------------------------------------------------
@ -70,6 +79,11 @@ func main() {
Dir: migrationsDir, 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 { app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
// serves static files from the provided public dir (if exists) // serves static files from the provided public dir (if exists)
e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS(publicDir), indexFallback)) e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS(publicDir), indexFallback))