Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
3ef14d8ac7 | |||
f332bf95fe | |||
6acad8a306 | |||
6ae672f707 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnginx",
|
"name": "@pushrocks/smartnginx",
|
||||||
"version": "2.0.15",
|
"version": "2.0.17",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnginx",
|
"name": "@pushrocks/smartnginx",
|
||||||
"version": "2.0.15",
|
"version": "2.0.17",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "control nginx from node, TypeScript ready",
|
"description": "control nginx from node, TypeScript ready",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -40,6 +40,12 @@ tap.test('.deploy() should deploy a config from an instance', async () => {
|
|||||||
await testSmartNginx.deploy();
|
await testSmartNginx.deploy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should not redeploy', async () => {
|
||||||
|
testSmartNginx.addHostCandidate(testNginxZone01);
|
||||||
|
testSmartNginx.addHostCandidate(testNginxZone02);
|
||||||
|
await testSmartNginx.deploy();
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('.stop() should end the process', async () => {
|
tap.test('.stop() should end the process', async () => {
|
||||||
testSmartNginx.nginxProcess.stop();
|
testSmartNginx.nginxProcess.stop();
|
||||||
});
|
});
|
||||||
|
@ -70,12 +70,12 @@ export class SmartNginx {
|
|||||||
* check wether there has been a diverging host configuration
|
* check wether there has been a diverging host configuration
|
||||||
* this function will only redeploy the nginx configuration in case there has been a change
|
* this function will only redeploy the nginx configuration in case there has been a change
|
||||||
*/
|
*/
|
||||||
private areHostsDiverged(): boolean {
|
private async areHostsDiverged(): Promise<boolean> {
|
||||||
let hostCounter = 0;
|
let hostCounter = 0;
|
||||||
let unfoundHosts = 0;
|
let unfoundHosts = 0;
|
||||||
this.hostCandidates.forEach(hostCandidateArg => {
|
await this.hostCandidates.forEach(async hostCandidateArg => {
|
||||||
let foundHost = false;
|
let foundHost = false;
|
||||||
this.deployedHosts.forEach(deployedHostArg => {
|
await this.deployedHosts.forEach(async deployedHostArg => {
|
||||||
if (
|
if (
|
||||||
hostCandidateArg.hostName === deployedHostArg.hostName &&
|
hostCandidateArg.hostName === deployedHostArg.hostName &&
|
||||||
hostCandidateArg.destination === deployedHostArg.destination
|
hostCandidateArg.destination === deployedHostArg.destination
|
||||||
@ -89,7 +89,7 @@ export class SmartNginx {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
this.deployedHosts.getArray.length !== this.hostCandidates.getArray().length ||
|
this.deployedHosts.getArray().length !== this.hostCandidates.getArray().length ||
|
||||||
hostCounter !== this.deployedHosts.getArray().length ||
|
hostCounter !== this.deployedHosts.getArray().length ||
|
||||||
unfoundHosts !== 0
|
unfoundHosts !== 0
|
||||||
);
|
);
|
||||||
@ -99,7 +99,7 @@ export class SmartNginx {
|
|||||||
* deploy the current stack and restart nginx
|
* deploy the current stack and restart nginx
|
||||||
*/
|
*/
|
||||||
public async deploy() {
|
public async deploy() {
|
||||||
if (this.areHostsDiverged()) {
|
if (await this.areHostsDiverged()) {
|
||||||
this.logger.log('ok', `hosts have diverged, trigger config deployment and nginx reload!`);
|
this.logger.log('ok', `hosts have diverged, trigger config deployment and nginx reload!`);
|
||||||
this.deployedHosts.wipe();
|
this.deployedHosts.wipe();
|
||||||
this.deployedHosts.addArray(this.hostCandidates.getArray());
|
this.deployedHosts.addArray(this.hostCandidates.getArray());
|
||||||
@ -118,6 +118,7 @@ export class SmartNginx {
|
|||||||
this.nginxProcess.reloadConfig();
|
this.nginxProcess.reloadConfig();
|
||||||
} else {
|
} else {
|
||||||
this.logger.log('info', `hosts have not diverged, skipping nginx reload`);
|
this.logger.log('info', `hosts have not diverged, skipping nginx reload`);
|
||||||
|
this.hostCandidates.wipe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user