Skip to content

Configuration ​

ts
const hookgres = new Hookgres({
  pool, // or connectionString
  schema: "hookgres",
  retrySchedule: DEFAULT_RETRY_SCHEDULE,
  requestTimeoutMs: 15_000,
  disableEndpointAfterMs: 5 * 24 * 60 * 60 * 1000,
  concurrency: 10,
  pollIntervalMs: 1_000,
  lockTimeoutMs: 45_000,
  secretRotationGraceMs: 24 * 60 * 60 * 1000,
  fetch: globalThis.fetch,
  userAgent: "Hookgres/0.1",
  onError: console.error,
});
OptionDefaultDescription
pool—A pg.Pool. Hookgres never closes a pool it didn't create.
connectionString—Used to create a pool when pool isn't given. close() ends it.
schema"hookgres"Postgres schema for the tables. Lowercase letters, digits and underscores, not starting with a digit, up to 63 characters.
retrySchedule5s, 5m, 30m, 2h, 5h, 10h, 10hWaits between attempts, in milliseconds. Attempts = length + 1.
requestTimeoutMs15000How long to wait for a response before the attempt counts as failed.
disableEndpointAfterMs5 daysDisable an endpoint after it has failed this long with no success. null never disables.
concurrency10Deliveries each worker claims and sends at once. Also the batch size of runOnce().
pollIntervalMs1000How long an idle worker waits before checking again. Sends from the same process wake it sooner.
lockTimeoutMsrequestTimeoutMs + 30sHow long a claimed delivery stays locked before another worker may retry it after a crash. Must be greater than requestTimeoutMs.
secretRotationGraceMs24 hoursDefault grace period for rotateEndpointSecret.
fetchglobalThis.fetchCustom fetch, for an SSRF guard, a proxy or tests.
userAgent"Hookgres/0.1"The user-agent header on every request.
onErrorconsole.errorCalled with unexpected worker errors, like a lost database connection. Failed deliveries are not errors.

The constructor throws if neither pool nor connectionString is given, if schema is invalid, if retrySchedule contains a negative or non-finite number, or if lockTimeoutMs isn't greater than requestTimeoutMs.

Several instances ​

Different schema values give you fully separate queues in the same database, for example one per environment or per product:

ts
const billing = new Hookgres({ pool, schema: "hookgres_billing" });
const platform = new Hookgres({ pool, schema: "hookgres_platform" });

All workers that use the same schema should use the same options, especially retrySchedule.

Released under the MIT License.