Giter Site home page Giter Site logo

node-wait-for-postgres's Introduction

Wait for Postgres

Waits for a PostgreSQL connection to become available, optionally running a custom query to determine if the connection is valid.

Installation

npm install --save wait-for-postgres

Usage

Run as a module within another script:

waitForPg = require 'wait-for-postgres'
config =
  username: user
  password: pass
  quiet: true
  query: 'SELECT 1'

waitForPg.wait(config)

Or run stand-alone

wait-for-postgres --username=user --password=pass --quiet

Building

cake build

node-wait-for-postgres's People

Contributors

joeledwards avatar

Stargazers

 avatar  avatar

Watchers

 avatar

node-wait-for-postgres's Issues

When connectionTimeout is not configured, await() gets into a spin-loop.

I have a configuration where the connectTimeout is missing. In that case I get 1000s of attempts to connect.

Excerpt without connectTimeout:
[Error: connection timeout] Attempt 1 timed out. Time elapsed: 10.354 ms
.
.
.
[Error: connection timeout] Attempt 6647 timed out. Time elapsed: 15.234 s
[Error: connection timeout] Attempt 6648 timed out. Time elapsed: 15.236 s
[Error: connection timeout] Attempt 6649 timed out. Time elapsed: 15.237 s
[Error: connection timeout] Attempt 6650 timed out. Time elapsed: 15.240 s
[Error: connection timeout] Attempt 6651 timed out. Time elapsed: 15.241 s
Connected. Running test query: 'SELECT 1'
Query done.
Query succeeded after 6652 attempt(s) over 15.252 s

Excerpt with connectTimeout:250 specified in the config:
Connected. Running test query: 'SELECT 1'
Query done.
Query succeeded after 1 attempt(s) over 21.804 ms

Since the default is 250, I would expect the behavior to be identical. I will need to check the code in a while as to the root-cause.

Connection strings are no longer supported by node >= 6.0

Node and node-postgres have stopped supporting connection strings (connection uris). See brianc/node-postgres#1141. node-wait-for-postgres creates a connection string out of a config object and so is no longer compatible as of node 6.0.

Edit: pardon my original confusion. It's not node-postgres 6.x that breaks it. Even using old node-postgres with nodejs 6.x breaks it.

[ReferenceError: client is not defined]

When polling for availability, the error message given is as above.

This seems to stem from this line, which references client despite it not being in scope

If you move this line up one, it should be OK I think:

client = new pg.Client uri

I would submit a PR but i'm not familiar enough with coffeescript to be confident in any changes

Version 1.5.0 of wait-for-postgres unavailable

(Please pardon my newbie understanding of npm)
I am unable to download / install this as the version seems unavailable. The package.json in the github repo does mention 1.5.0. I believe this has to be released in the npm registry.

The reason I need this is due to issues in the connectTimeout when it's not specified (i.e., the default value is expected to be used). I get a busy wait when the connectTimeout is not specified while when the connectTimeout:250 is specified, the wait is not busy and clean. I expect that v1.5.0 with its overhaul in timeout logic will fix it.

npm view wait-for-postgres

{ name: 'wait-for-postgres',
description: 'Wait for a Postgres connection to become available',
'dist-tags': { latest: '1.4.0' },
versions: [ '1.1.0', '1.2.0', '1.2.1', '1.2.2', '1.3.0', '1.4.0' ],
maintainers: [ 'buzuli [email protected]' ],
time:
{ modified: '2016-06-14T18:09:17.958Z',
created: '2015-05-14T09:14:54.947Z',
'1.1.0': '2015-05-14T09:14:54.947Z',
'1.2.0': '2015-05-14T20:39:14.264Z',
'1.2.1': '2015-05-15T17:11:52.540Z',
'1.2.2': '2015-05-20T03:33:49.823Z',
'1.3.0': '2015-09-01T21:15:59.777Z',
'1.4.0': '2016-06-14T18:09:17.958Z' },
homepage: 'https://github.com/joeledwards/node-wait-for-postgres#readme',
keywords: [ 'Postgres', 'Notify', 'Event' ],
repository:
{ type: 'git',
url: 'git+https://github.com/joeledwards/node-wait-for-postgres.git' },
contributors: [ 'Joel Edwards [email protected] (https://github.com/joeledwards)' ],
author: 'Joel Edwards (https://github.com/joeledwards)',
bugs: { url: 'https://github.com/joeledwards/node-wait-for-postgres/issues' },
readmeFilename: 'README.md',
version: '1.4.0',
licenses:
[ { type: 'MIT',
url: 'https://github.com/joeledwards/node-durations/blob/master/LICENSE' } ],
main: './lib/index',
directories: { lib: './lib' },
bin:
{ 'wait-for-postgres': './bin/wait-for-postgres',
wait4pg: './bin/wait-for-postgres' },
dependencies:
{ commander: '^2.9.0',
durations: '^2.2.0',
pg: '^5.1.0',
q: '^1.4.1' },
devDependencies: { 'coffee-script': '^1.10.0', mocha: '^2.5.3' },
scripts:
{ prepublish: 'cake build',
build: 'cake build',
test: 'cake test' },
engines: { node: '>=0.10' },
gitHead: '16fc2de95b3eeb7df6c6f5b81936655e26a7586c',
dist:
{ shasum: 'd27af80239dba772b2219b503667e37cd6f308e3',
tarball: 'https://registry.npmjs.org/wait-for-postgres/-/wait-for-postgres-1.4.0.tgz' } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.