[next] Websocket Keep Alive (#2394)

* feat: added keepalive config

* fix: format

* fix: adjusted client timeout default

* Update server.ts
This commit is contained in:
Wyatt Johnson
2019-07-09 16:27:58 +00:00
committed by GitHub
parent 9a191b44ba
commit 9e55ea66fa
4 changed files with 20 additions and 0 deletions
+3
View File
@@ -385,6 +385,9 @@ the variables in a `.env` file in the root of the project in a simple
- `CLUSTER_METRICS_PORT` - If `CONCURRENCY` is more than `1`, the metrics are provided at this port under `/cluster_metrics`. (Default `3001`)
- `DISABLE_LIVE_UPDATES` - When `true`, disables subscriptions for the comment
stream for all stories across all tenants (Default `false`)
- `WEBSOCKET_KEEP_ALIVE_TIMEOUT` - A duration in a parsable format (e.g. `30 seconds`
, `1 minute`) that should be used to send keep alive messages through the
websocket to keep the socket alive (Default `30 seconds`)
## License
@@ -89,6 +89,7 @@ export default function createManagedSubscriptionClient(
if (!subscriptionClient) {
subscriptionClient = new SubscriptionClient(url, {
reconnect: true,
timeout: 60000,
connectionCallback: err => {
if (err) {
// If an error is thrown as a result of live updates being
+8
View File
@@ -173,6 +173,14 @@ const config = convict({
env: "STATIC_URI",
arg: "staticUri",
},
websocket_keep_alive_timeout: {
doc:
"The keepalive timeout (in ms) that should be used to send keep alive messages through the websocket to keep the socket alive",
format: "duration",
default: "30 seconds",
env: "WEBSOCKET_KEEP_ALIVE_TIMEOUT",
arg: "websocketKeepAliveTimeout",
},
disable_tenant_caching: {
doc:
"Disables the tenant caching, all tenants will be loaded from MongoDB each time it's needed",
@@ -223,6 +223,13 @@ export function createSubscriptionServer(
schema: GraphQLSchema,
options: Options
) {
const keepAlive = options.config.get("websocket_keep_alive_timeout");
if (typeof keepAlive !== "number" || keepAlive <= 0) {
throw new Error(
"expected the websocket_keep_alive_timeout configuration to be a positive number"
);
}
return SubscriptionServer.create(
{
schema,
@@ -230,6 +237,7 @@ export function createSubscriptionServer(
subscribe,
onConnect: onConnect(options),
onOperation: onOperation(options),
keepAlive,
},
{
server,