Skip to content

Commit

Permalink
feat (client): configurable subscription timeout (#637)
Browse files Browse the repository at this point in the history
This PR adds an option to electrify to configure the timeout for
subscriptions as requested in
#605
  • Loading branch information
kevin-dp authored Nov 9, 2023
1 parent 5da426d commit 9583d21
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
13 changes: 11 additions & 2 deletions clients/typescript/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ export interface ElectricConfig {
* ssl is enabled or 80 when it isn't.
*
* Defaults to:
* `http://127.0.0.1:5133`
* `http://localhost:5133`
*/
url?: string
/**
* Timeout (in milliseconds) for RPC requests.
* Needs to be large enough for the server to have time to deliver the full initial subscription data
* when the client subscribes to a shape for the first time.
*/
timeout?: number
/**
* Optional flag to activate debug mode
* which produces more verbose output.
Expand All @@ -40,6 +46,7 @@ export type HydratedConfig = {
host: string
port: number
ssl: boolean
timeout: number
}
debug: boolean
connectionBackOffOptions: ConnectionBackOffOptions
Expand All @@ -51,6 +58,7 @@ export type InternalElectricConfig = {
host: string
port: number
ssl: boolean
timeout: number
}
debug?: boolean
connectionBackOffOptions?: ConnectionBackOffOptions
Expand All @@ -63,7 +71,7 @@ export const hydrateConfig = (config: ElectricConfig): HydratedConfig => {
}

const debug = config.debug ?? false
const url = new URL(config.url ?? 'http://127.0.0.1:5133')
const url = new URL(config.url ?? 'http://localhost:5133')

const isSecureProtocol = url.protocol === 'https:' || url.protocol === 'wss:'
const sslEnabled = isSecureProtocol || url.searchParams.get('ssl') === 'true'
Expand All @@ -76,6 +84,7 @@ export const hydrateConfig = (config: ElectricConfig): HydratedConfig => {
host: url.hostname,
port: port,
ssl: sslEnabled,
timeout: config.timeout ?? 3000,
}

const {
Expand Down
3 changes: 1 addition & 2 deletions clients/typescript/src/satellite/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ export const satelliteDefaults: SatelliteOpts = {
}

export const satelliteClientDefaults = {
timeout: 3000,
pushPeriod: 500,
}

export interface SatelliteClientOpts {
host: string
port: number
ssl: boolean
timeout?: number
timeout: number
pushPeriod?: number
}

Expand Down
3 changes: 1 addition & 2 deletions clients/typescript/src/satellite/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SatelliteClientOpts,
SatelliteOpts,
SatelliteOverrides,
satelliteClientDefaults,
satelliteDefaults,
validateConfig,
} from './config'
Expand Down Expand Up @@ -205,10 +204,10 @@ export class GlobalRegistry extends BaseRegistry {
}

const satelliteClientOpts: SatelliteClientOpts = {
...satelliteClientDefaults,
host: config.replication.host,
port: config.replication.port,
ssl: config.replication.ssl,
timeout: config.replication.timeout,
}

const client = new SatelliteClient(
Expand Down
3 changes: 2 additions & 1 deletion clients/typescript/test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ test('hydrateConfig adds expected defaults', async (t) => {
},
})

t.is(hydrated.replication.host, '127.0.0.1')
t.is(hydrated.replication.host, 'localhost')
t.is(hydrated.replication.port, 5133)
t.is(hydrated.replication.ssl, false)
t.is(hydrated.replication.timeout, 3000)

t.is(hydrated.auth.token, 'test-token')

Expand Down

0 comments on commit 9583d21

Please sign in to comment.