await-pg-cli
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -10,5 +10,6 @@ #!/usr/bin/env node | ||
var update_notifier_1 = __importDefault(require("update-notifier")); | ||
// eslint-disable-next-line import/order | ||
var index_1 = require("./index"); | ||
// tslint:disable-next-line:no-var-requires | ||
var pkg = require("../package.json"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
var pkg = require('../package.json'); | ||
// Notify for updates | ||
@@ -20,10 +21,10 @@ if (pkg.version) { | ||
commander_1.default | ||
.version(pkg.version || "dev") | ||
.option("-c, --connection <connection>", "Set connection string") | ||
.option("-d, --delay <delay>", "Set delay in seconds", 3) | ||
.option("-t, --timeout <timeout>", "Set timeout in seconds", 60); | ||
.version(pkg.version || 'dev') | ||
.option('-c, --connection <connection>', 'Set connection string') | ||
.option('-d, --delay <delay>', 'Set delay in seconds', 3) | ||
.option('-t, --timeout <timeout>', 'Set timeout in seconds', 60); | ||
// process args | ||
commander_1.default.parse(process.argv); | ||
// run | ||
console.log(chalk_1.default.white.bold("await pg") + " " + chalk_1.default.gray("(" + (pkg.version || "dev") + ")")); | ||
console.log(chalk_1.default.white.bold("await pg") + " " + chalk_1.default.gray("(" + (pkg.version || 'dev') + ")")); | ||
index_1.awaitReadyDatabase({ | ||
@@ -37,3 +38,3 @@ connectionString: commander_1.default.connection, | ||
}).catch(function (e) { | ||
if (e === "timeout") { | ||
if (e === 'timeout') { | ||
console.log("" + chalk_1.default.red("connection timed out after " + commander_1.default.timeout + " seconds")); | ||
@@ -40,0 +41,0 @@ } |
@@ -0,1 +1,2 @@ | ||
export declare function tryConnectDatabase(connectionString: string): Promise<void>; | ||
export declare function awaitReadyDatabase(options: { | ||
@@ -6,2 +7,1 @@ connectionString: string; | ||
}): Promise<{}>; | ||
export declare function tryConnectDatabase(connectionString: string): Promise<void>; |
@@ -39,2 +39,23 @@ "use strict"; | ||
var pg_1 = require("pg"); | ||
function tryConnectDatabase(connectionString) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var client; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
client = new pg_1.Client({ | ||
connectionString: connectionString, | ||
}); | ||
return [4 /*yield*/, client.connect()]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, client.end()]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.tryConnectDatabase = tryConnectDatabase; | ||
function awaitReadyDatabase(options) { | ||
@@ -45,3 +66,3 @@ return new Promise(function (resolve, reject) { | ||
if (Date.now() > timeOutAt) { | ||
reject("timeout"); | ||
reject('timeout'); | ||
} | ||
@@ -54,7 +75,11 @@ else { | ||
.catch(function (e) { | ||
if (e.code === "ECONNREFUSED") { | ||
if (e.code === '57P03') { | ||
console.log("database system is starting up, retrying in " + options.delay + "s"); | ||
setTimeout(fn, options.delay * 1000); | ||
} | ||
else if (e.code === 'ECONNREFUSED') { | ||
console.log("connection refused, retrying in " + options.delay + "s"); | ||
setTimeout(fn, options.delay * 1000); | ||
} | ||
else if (e.toString().includes("Connection terminated unexpectedly")) { | ||
else if (e.toString().includes('Connection terminated unexpectedly')) { | ||
console.log("connection terminated unexpectedly, retrying in " + options.delay + "s"); | ||
@@ -74,23 +99,2 @@ setTimeout(fn, options.delay * 1000); | ||
exports.awaitReadyDatabase = awaitReadyDatabase; | ||
function tryConnectDatabase(connectionString) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var client; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
client = new pg_1.Client({ | ||
connectionString: connectionString, | ||
}); | ||
return [4 /*yield*/, client.connect()]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, client.end()]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.tryConnectDatabase = tryConnectDatabase; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "await-pg-cli", | ||
"description": "CLI utility to await a postgres database to be ready", | ||
"version": "1.0.1", | ||
"main": "build/index.js", | ||
"version": "1.0.0", | ||
"typings": "build/index.d.ts", | ||
@@ -14,7 +14,8 @@ "bin": { | ||
"build": "tsc", | ||
"lint": "eslint --ext=ts,tsx src", | ||
"lint:fix": "eslint --ext=ts,tsx src --fix", | ||
"start": "ts-node src/cli.ts", | ||
"semantic-release": "semantic-release", | ||
"test:watch": "jest --watch", | ||
"tslint": "tslint -p . -t stylish", | ||
"tslint:fix": "npm run tslint -s -- --fix" | ||
"test": "jest --coverage", | ||
"test:watch": "jest --watch" | ||
}, | ||
@@ -39,3 +40,7 @@ "files": [ | ||
"@types/update-notifier": "^2.5.0", | ||
"@typescript-eslint/eslint-plugin": "^2.18.0", | ||
"@typescript-eslint/parser": "^2.18.0", | ||
"babel-jest": "^24.8.0", | ||
"eslint": "^6.8.0", | ||
"eslint-plugin-import": "^2.20.0", | ||
"jest": "^24.8.0", | ||
@@ -46,3 +51,2 @@ "rimraf": "^2.6.3", | ||
"ts-node": "^8.1.0", | ||
"tslint": "^5.16.0", | ||
"typescript": "^3.4.5" | ||
@@ -49,0 +53,0 @@ }, |
8472
149
15