Add config option for pool timeout (#1280)

This commit is contained in:
Xavier Francisco
2019-04-25 12:23:20 -05:00
committed by Steve Chávez
parent 2044f77d49
commit d32f373e1e
4 changed files with 14 additions and 3 deletions
+2
View File
@@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #690, Add `?columns` query parameter for faster bulk inserts, also ignores unspecified json keys in a payload - @steve-chavez - #690, Add `?columns` query parameter for faster bulk inserts, also ignores unspecified json keys in a payload - @steve-chavez
- #1239, Add support for resource embedding on materialized views - @vitorbaptista - #1239, Add support for resource embedding on materialized views - @vitorbaptista
- #1264, Add support for bulk RPC call - @steve-chavez - #1264, Add support for bulk RPC call - @steve-chavez
- #1278, Add db-pool-timeout config option - @qu4tro
### Fixed ### Fixed
@@ -19,6 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #1238, Fix PostgreSQL to OpenAPI type mappings for numeric and character types - @fpusch - #1238, Fix PostgreSQL to OpenAPI type mappings for numeric and character types - @fpusch
- #1265, Fix query generated on bulk upsert with an empty array - @qu4tro - #1265, Fix query generated on bulk upsert with an empty array - @qu4tro
- #1273, Fix RPC ignoring unknown arguments by default - @steve-chavez - #1273, Fix RPC ignoring unknown arguments by default - @steve-chavez
- #1257, Fix incorrect status when a PATCH request doesn't find rows to change - @qu4tro
## [5.2.0] - 2018-12-12 ## [5.2.0] - 2018-12-12
+2 -2
View File
@@ -4,7 +4,7 @@ module Main where
import PostgREST.App (postgrest) import PostgREST.App (postgrest)
import PostgREST.Config (AppConfig (..), import PostgREST.Config (AppConfig (..), configPoolTimeout',
prettyVersion, readOptions) prettyVersion, readOptions)
import PostgREST.DbStructure (getDbStructure, getPgVersion) import PostgREST.DbStructure (getDbStructure, getPgVersion)
import PostgREST.Error (encodeError) import PostgREST.Error (encodeError)
@@ -164,7 +164,7 @@ main = do
-- --
-- create connection pool with the provided settings, returns either -- create connection pool with the provided settings, returns either
-- a 'Connection' or a 'ConnectionError'. Does not throw. -- a 'Connection' or a 'ConnectionError'. Does not throw.
pool <- P.acquire (configPool conf, 10, pgSettings) pool <- P.acquire (configPool conf, configPoolTimeout' conf, pgSettings)
-- --
-- To be filled in by connectionWorker -- To be filled in by connectionWorker
refDbStructure <- newIORef Nothing refDbStructure <- newIORef Nothing
+9
View File
@@ -19,6 +19,7 @@ module PostgREST.Config ( prettyVersion
, readOptions , readOptions
, corsPolicy , corsPolicy
, AppConfig (..) , AppConfig (..)
, configPoolTimeout'
) )
where where
@@ -73,6 +74,7 @@ data AppConfig = AppConfig {
, configJwtAudience :: Maybe StringOrURI , configJwtAudience :: Maybe StringOrURI
, configPool :: Int , configPool :: Int
, configPoolTimeout :: Int
, configMaxRows :: Maybe Integer , configMaxRows :: Maybe Integer
, configReqCheck :: Maybe Text , configReqCheck :: Maybe Text
, configQuiet :: Bool , configQuiet :: Bool
@@ -81,6 +83,11 @@ data AppConfig = AppConfig {
, configExtraSearchPath :: [Text] , configExtraSearchPath :: [Text]
} }
configPoolTimeout' :: (Fractional a) => AppConfig -> a
configPoolTimeout' =
fromRational . toRational . configPoolTimeout
defaultCorsPolicy :: CorsResourcePolicy defaultCorsPolicy :: CorsResourcePolicy
defaultCorsPolicy = CorsResourcePolicy Nothing defaultCorsPolicy = CorsResourcePolicy Nothing
["GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS"] ["Authorization"] Nothing ["GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS"] ["Authorization"] Nothing
@@ -136,6 +143,7 @@ readOptions = do
<*> (fromMaybe False . join . fmap coerceBool <$> C.key "secret-is-base64") <*> (fromMaybe False . join . fmap coerceBool <$> C.key "secret-is-base64")
<*> parseJwtAudience "jwt-aud" <*> parseJwtAudience "jwt-aud"
<*> (fromMaybe 10 . join . fmap coerceInt <$> C.key "db-pool") <*> (fromMaybe 10 . join . fmap coerceInt <$> C.key "db-pool")
<*> (fromMaybe 10 . join . fmap coerceInt <$> C.key "db-pool-timeout")
<*> (join . fmap coerceInt <$> C.key "max-rows") <*> (join . fmap coerceInt <$> C.key "max-rows")
<*> (mfilter (/= "") <$> C.key "pre-request") <*> (mfilter (/= "") <$> C.key "pre-request")
<*> pure False <*> pure False
@@ -208,6 +216,7 @@ readOptions = do
|db-schema = "public" # this schema gets added to the search_path of every request |db-schema = "public" # this schema gets added to the search_path of every request
|db-anon-role = "postgres" |db-anon-role = "postgres"
|db-pool = 10 |db-pool = 10
|db-pool-timeout = 10
| |
|server-host = "127.0.0.1" |server-host = "127.0.0.1"
|server-port = 3000 |server-port = 3000
+1 -1
View File
@@ -70,7 +70,7 @@ _baseCfg = -- Connection Settings
-- Jwt settings -- Jwt settings
(Just $ encodeUtf8 "reallyreallyreallyreallyverysafe") False Nothing (Just $ encodeUtf8 "reallyreallyreallyreallyverysafe") False Nothing
-- Connection Modifiers -- Connection Modifiers
10 Nothing (Just "test.switch_role") 10 10 Nothing (Just "test.switch_role")
-- Debug Settings -- Debug Settings
True True
[ ("app.settings.app_host", "localhost") [ ("app.settings.app_host", "localhost")