diff --git a/package-lock.json b/package-lock.json index 6283a64..9adc33a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,28 +1,28 @@ { "name": "barky", - "version": "1.0.47", + "version": "1.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "barky", - "version": "1.0.47", + "version": "1.1.1", "license": "MIT", "dependencies": { - "axios": "^1.6.0", + "axios": "^1.6.2", "dotenv": "^16.3.1", "knex": "^3.0.1", - "mysql2": "^3.6.2", + "mysql2": "^3.6.3", "sqlite3": "^5.1.6", "tslib": "^2.6.2", - "yaml": "^2.3.3", + "yaml": "^2.3.4", "yargs": "^17.7.2" }, "bin": { "barky": "dist/cli.js" }, "devDependencies": { - "@babel/core": "^7.23.2", + "@babel/core": "^7.23.3", "@babel/preset-env": "^7.23.2", "@types/jest": "^29.5.7", "@types/node": "^20.8.10", @@ -141,21 +141,21 @@ } }, "node_modules/@babel/core": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.2.tgz", - "integrity": "sha512-n7s51eWdaWZ3vGT2tD4T7J6eJs3QoBXydv7vkUM06Bf1cbVD2Kc2UrkzhiQwobfV7NwOnQXYL7UBJ5VPU+RGoQ==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.3.tgz", + "integrity": "sha512-Jg+msLuNuCJDyBvFv5+OKOUjWMZgd85bKjbICd3zWrKAo+bJ49HJufi7CQE0q0uR8NGyO6xkCACScNqyjHSZew==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.22.13", - "@babel/generator": "^7.23.0", + "@babel/generator": "^7.23.3", "@babel/helper-compilation-targets": "^7.22.15", - "@babel/helper-module-transforms": "^7.23.0", + "@babel/helper-module-transforms": "^7.23.3", "@babel/helpers": "^7.23.2", - "@babel/parser": "^7.23.0", + "@babel/parser": "^7.23.3", "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.2", - "@babel/types": "^7.23.0", + "@babel/traverse": "^7.23.3", + "@babel/types": "^7.23.3", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -171,12 +171,12 @@ } }, "node_modules/@babel/generator": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz", - "integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.3.tgz", + "integrity": "sha512-keeZWAV4LU3tW0qRi19HRpabC/ilM0HRBBzf9/k8FFiG4KVpiv0FIy4hHfLfFQZNhziCTPTmd59zoyv6DNISzg==", "dev": true, "dependencies": { - "@babel/types": "^7.23.0", + "@babel/types": "^7.23.3", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -340,9 +340,9 @@ } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.0.tgz", - "integrity": "sha512-WhDWw1tdrlT0gMgUJSlX0IQvoO1eN279zrAUbVB+KpV2c3Tylz8+GnKOLllCS6Z/iZQEyVYxhZVUdPTqs2YYPw==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.3.tgz", + "integrity": "sha512-7bBs4ED9OmswdfDzpz4MpWgSrV7FXlc3zIagvLFjS5H+Mk7Snr21vQ6QwrsoCGMfNC4e4LQPdoULEt4ykz0SRQ==", "dev": true, "dependencies": { "@babel/helper-environment-visitor": "^7.22.20", @@ -590,9 +590,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", - "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.3.tgz", + "integrity": "sha512-uVsWNvlVsIninV2prNz/3lHCb+5CJ+e+IUBfbjToAHODtfGYLfCFuY4AU7TskI+dAKk+njsPiBjq1gKTvZOBaw==", "dev": true, "bin": { "parser": "bin/babel-parser.js" @@ -1835,19 +1835,19 @@ } }, "node_modules/@babel/traverse": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz", - "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.3.tgz", + "integrity": "sha512-+K0yF1/9yR0oHdE0StHuEj3uTPzwwbrLGfNOndVJVV2TqA5+j3oljJUb4nmB954FLGjNem976+B+eDuLIjesiQ==", "dev": true, "dependencies": { "@babel/code-frame": "^7.22.13", - "@babel/generator": "^7.23.0", + "@babel/generator": "^7.23.3", "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-function-name": "^7.23.0", "@babel/helper-hoist-variables": "^7.22.5", "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/parser": "^7.23.0", - "@babel/types": "^7.23.0", + "@babel/parser": "^7.23.3", + "@babel/types": "^7.23.3", "debug": "^4.1.0", "globals": "^11.1.0" }, @@ -1856,9 +1856,9 @@ } }, "node_modules/@babel/types": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", - "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.3.tgz", + "integrity": "sha512-OZnvoH2l8PK5eUvEcUyCt/sXgr/h+UWpVuBbOljwcrAgUl6lpchoQ++PHGyQy1AtYnVA6CEq3y5xeEI10brpXw==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.22.5", @@ -2752,9 +2752,9 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.0.tgz", - "integrity": "sha512-EZ1DYihju9pwVB+jg67ogm+Tmqc6JmhamRN6I4Zt8DfZu5lbcQGw3ozH9lFejSJgs/ibaef3A9PMXPLeefFGJg==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "dependencies": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", @@ -5083,9 +5083,9 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/mysql2": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.6.2.tgz", - "integrity": "sha512-m5erE6bMoWfPXW1D5UrVwlT8PowAoSX69KcZzPuARQ3wY1RJ52NW9PdvdPo076XiSIkQ5IBTis7hxdlrQTlyug==", + "version": "3.6.3", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.6.3.tgz", + "integrity": "sha512-qYd/1CDuW1KYZjD4tzg2O8YS3X/UWuGH8ZMHyMeggMTXL3yOdMisbwZ5SNkHzDGlZXKYLAvV8tMrEH+NUMz3fw==", "dependencies": { "denque": "^2.1.0", "generate-function": "^2.3.1", @@ -6536,9 +6536,9 @@ "dev": true }, "node_modules/yaml": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.3.tgz", - "integrity": "sha512-zw0VAJxgeZ6+++/su5AFoqBbZbrEakwu+X0M5HmcwUiBL7AzcuPKjj5we4xfQLp78LkEMpD0cOnUhmgOVy3KdQ==", + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.4.tgz", + "integrity": "sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==", "engines": { "node": ">= 14" } @@ -6676,21 +6676,21 @@ "dev": true }, "@babel/core": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.2.tgz", - "integrity": "sha512-n7s51eWdaWZ3vGT2tD4T7J6eJs3QoBXydv7vkUM06Bf1cbVD2Kc2UrkzhiQwobfV7NwOnQXYL7UBJ5VPU+RGoQ==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.3.tgz", + "integrity": "sha512-Jg+msLuNuCJDyBvFv5+OKOUjWMZgd85bKjbICd3zWrKAo+bJ49HJufi7CQE0q0uR8NGyO6xkCACScNqyjHSZew==", "dev": true, "requires": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.22.13", - "@babel/generator": "^7.23.0", + "@babel/generator": "^7.23.3", "@babel/helper-compilation-targets": "^7.22.15", - "@babel/helper-module-transforms": "^7.23.0", + "@babel/helper-module-transforms": "^7.23.3", "@babel/helpers": "^7.23.2", - "@babel/parser": "^7.23.0", + "@babel/parser": "^7.23.3", "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.2", - "@babel/types": "^7.23.0", + "@babel/traverse": "^7.23.3", + "@babel/types": "^7.23.3", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -6699,12 +6699,12 @@ } }, "@babel/generator": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz", - "integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.3.tgz", + "integrity": "sha512-keeZWAV4LU3tW0qRi19HRpabC/ilM0HRBBzf9/k8FFiG4KVpiv0FIy4hHfLfFQZNhziCTPTmd59zoyv6DNISzg==", "dev": true, "requires": { - "@babel/types": "^7.23.0", + "@babel/types": "^7.23.3", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -6826,9 +6826,9 @@ } }, "@babel/helper-module-transforms": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.0.tgz", - "integrity": "sha512-WhDWw1tdrlT0gMgUJSlX0IQvoO1eN279zrAUbVB+KpV2c3Tylz8+GnKOLllCS6Z/iZQEyVYxhZVUdPTqs2YYPw==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.3.tgz", + "integrity": "sha512-7bBs4ED9OmswdfDzpz4MpWgSrV7FXlc3zIagvLFjS5H+Mk7Snr21vQ6QwrsoCGMfNC4e4LQPdoULEt4ykz0SRQ==", "dev": true, "requires": { "@babel/helper-environment-visitor": "^7.22.20", @@ -7012,9 +7012,9 @@ } }, "@babel/parser": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", - "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.3.tgz", + "integrity": "sha512-uVsWNvlVsIninV2prNz/3lHCb+5CJ+e+IUBfbjToAHODtfGYLfCFuY4AU7TskI+dAKk+njsPiBjq1gKTvZOBaw==", "dev": true }, "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": { @@ -7844,27 +7844,27 @@ } }, "@babel/traverse": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz", - "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.3.tgz", + "integrity": "sha512-+K0yF1/9yR0oHdE0StHuEj3uTPzwwbrLGfNOndVJVV2TqA5+j3oljJUb4nmB954FLGjNem976+B+eDuLIjesiQ==", "dev": true, "requires": { "@babel/code-frame": "^7.22.13", - "@babel/generator": "^7.23.0", + "@babel/generator": "^7.23.3", "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-function-name": "^7.23.0", "@babel/helper-hoist-variables": "^7.22.5", "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/parser": "^7.23.0", - "@babel/types": "^7.23.0", + "@babel/parser": "^7.23.3", + "@babel/types": "^7.23.3", "debug": "^4.1.0", "globals": "^11.1.0" } }, "@babel/types": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", - "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.3.tgz", + "integrity": "sha512-OZnvoH2l8PK5eUvEcUyCt/sXgr/h+UWpVuBbOljwcrAgUl6lpchoQ++PHGyQy1AtYnVA6CEq3y5xeEI10brpXw==", "dev": true, "requires": { "@babel/helper-string-parser": "^7.22.5", @@ -8601,9 +8601,9 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "axios": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.0.tgz", - "integrity": "sha512-EZ1DYihju9pwVB+jg67ogm+Tmqc6JmhamRN6I4Zt8DfZu5lbcQGw3ozH9lFejSJgs/ibaef3A9PMXPLeefFGJg==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "requires": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", @@ -10337,9 +10337,9 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "mysql2": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.6.2.tgz", - "integrity": "sha512-m5erE6bMoWfPXW1D5UrVwlT8PowAoSX69KcZzPuARQ3wY1RJ52NW9PdvdPo076XiSIkQ5IBTis7hxdlrQTlyug==", + "version": "3.6.3", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.6.3.tgz", + "integrity": "sha512-qYd/1CDuW1KYZjD4tzg2O8YS3X/UWuGH8ZMHyMeggMTXL3yOdMisbwZ5SNkHzDGlZXKYLAvV8tMrEH+NUMz3fw==", "requires": { "denque": "^2.1.0", "generate-function": "^2.3.1", @@ -11376,9 +11376,9 @@ "dev": true }, "yaml": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.3.tgz", - "integrity": "sha512-zw0VAJxgeZ6+++/su5AFoqBbZbrEakwu+X0M5HmcwUiBL7AzcuPKjj5we4xfQLp78LkEMpD0cOnUhmgOVy3KdQ==" + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.4.tgz", + "integrity": "sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==" }, "yargs": { "version": "17.7.2", diff --git a/package.json b/package.json index b86a591..50497de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "barky", - "version": "1.1.1", + "version": "1.1.2", "description": "A simple cloud services watchdog with digest notification support & no external dependencies", "homepage": "https://github.com/Rohland/barky#readme", "main": "dist/cli.js", @@ -16,17 +16,17 @@ "author": "", "license": "MIT", "dependencies": { - "axios": "^1.6.0", + "axios": "^1.6.2", "dotenv": "^16.3.1", "knex": "^3.0.1", - "mysql2": "^3.6.2", + "mysql2": "^3.6.3", "sqlite3": "^5.1.6", "tslib": "^2.6.2", - "yaml": "^2.3.3", + "yaml": "^2.3.4", "yargs": "^17.7.2" }, "devDependencies": { - "@babel/core": "^7.23.2", + "@babel/core": "^7.23.3", "@babel/preset-env": "^7.23.2", "@types/jest": "^29.5.7", "@types/node": "^20.8.10", diff --git a/src/evaluation.spec.ts b/src/evaluation.spec.ts index 90933ea..6f3d547 100644 --- a/src/evaluation.spec.ts +++ b/src/evaluation.spec.ts @@ -149,7 +149,7 @@ describe("evaluation", () => { const results = await evaluateType(type); // assert - expect(results.length).toEqual(2); + expect(results.length).toEqual(3); expect(results[0]).toMatchObject({ type: "web", label: "monitor", @@ -171,6 +171,17 @@ describe("evaluation", () => { alert: null, success: true }); + expect(results[2]).toMatchObject({ + type: "web", + label: "monitor", + identifier: "test", + result: 1, + timeTaken: 0, + resultMsg: "Skipped", + app: app, + alert: null, + success: true + }); }); }); }); diff --git a/src/evaluators/base.spec.ts b/src/evaluators/base.spec.ts index 6b94449..09ed15d 100644 --- a/src/evaluators/base.spec.ts +++ b/src/evaluators/base.spec.ts @@ -151,19 +151,27 @@ describe("base evaluator", () => { expect(apps1).toMatchObject([app]); expect(apps2).toMatchObject([]); expect(apps3).toMatchObject([app]); - expect(evaluator.skippedApps).toMatchObject([{ - ...app, - type: "custom", - label: "app1", - identifier: "*" - }]); + expect(evaluator.skippedApps).toMatchObject([ + { + ...app, + type: "custom", + label: "app1", + identifier: "*" + }, + { + ...app, + type: "custom", + label: "monitor", + identifier: "app1" + } + ]); }); }); - describe("if every 90s", () => { - it("should only be evaluated every 3rd invocation", async () => { + describe("if every 5m", () => { + it("should only be evaluated every 10th invocation", async () => { // arrange const app = { - every: "90s" + every: "5m" }; const evaluator = new CustomEvaluator({ "custom": { @@ -172,29 +180,21 @@ describe("base evaluator", () => { }); // act - const apps1 = evaluator.getAppsToEvaluate(); - const apps2 = evaluator.getAppsToEvaluate(); - const apps3 = evaluator.getAppsToEvaluate(); - const apps4 = evaluator.getAppsToEvaluate(); + const calls = 10; + const results = []; + for (let i = 0; i <= calls; i++) { + results.push(evaluator.getAppsToEvaluate()); + } // assert - expect(apps1).toMatchObject([app]); - expect(apps2).toMatchObject([]); - expect(apps3).toMatchObject([]); - expect(apps4).toMatchObject([app]); - expect(evaluator.skippedApps).toMatchObject([ - { - ...app, - type: "custom", - label: "app1", - identifier: "*" - }, - { - ...app, - type: "custom", - label: "app1", - identifier: "*" - }]); + expect(results[0]).toMatchObject([app]); + for (let i = 1; i < calls; i++) { + expect(results[i]).toMatchObject([]); + } + expect(results[10]).toMatchObject([app]) + expect(evaluator.skippedApps.length).toEqual(18); + expect(evaluator.skippedApps.filter(x => x.type ==="custom" && x.label === "app1" && x.identifier === "*").length).toEqual(9); + expect(evaluator.skippedApps.filter(x => x.type ==="custom" && x.label === "monitor" && x.identifier === "app1").length).toEqual(9); }); }); }); diff --git a/src/evaluators/base.ts b/src/evaluators/base.ts index 45326a7..4e530dc 100644 --- a/src/evaluators/base.ts +++ b/src/evaluators/base.ts @@ -154,6 +154,15 @@ export abstract class BaseEvaluator { ...app, ...this.generateSkippedAppUniqueKey(app.name) }); + // since we don't run, indicate monitor failure also skipped + this.skippedApps.push({ + ...app, + ...{ + type: app.type, + label: "monitor", + identifier: app.name + } + }); } return shouldEvaluate; } diff --git a/src/loop.ts b/src/loop.ts index 4afd0cc..6cb53d0 100644 --- a/src/loop.ts +++ b/src/loop.ts @@ -2,7 +2,6 @@ import { sleepMs } from "./lib/sleep"; import { startClock, stopClock } from "./lib/profiler"; import { canLockProcessFor } from "./lib/process-lock"; - export const LoopMs = 30000; export async function loop( diff --git a/src/models/db.spec.ts b/src/models/db.spec.ts index 1b38c13..ff602fd 100644 --- a/src/models/db.spec.ts +++ b/src/models/db.spec.ts @@ -51,6 +51,13 @@ describe("persistResults", () => { await verifySnapshotTableExists(); }); }); + describe("if different context provided", () => { + it("should throw", async () => { + // arrange + // act + expect(() => getConnection("test")).toThrow("Sqlite connection already established with context dbtests and now requesting test"); + }); + }); describe("persistResults", () => { describe("if has results", () => { describe.each([ diff --git a/src/models/db.ts b/src/models/db.ts index 2745da3..420ef92 100644 --- a/src/models/db.ts +++ b/src/models/db.ts @@ -7,6 +7,7 @@ import { AlertState } from "./alerts"; import path from "path"; let _connection; +let _context; export async function initConnection(name: string) { if (_connection) { @@ -22,6 +23,7 @@ export async function destroy() { } catch { // no-op } finally { + _context = null; _connection = null; } } @@ -87,7 +89,9 @@ export async function mutateAndPersistSnapshotState( snapshots: Snapshot[], logIdsToDelete: number[]) { await _connection.transaction(async trx => { - logIdsToDelete?.length > 0 && await trx("logs").whereIn("id", logIdsToDelete).del(); + if (logIdsToDelete?.length > 0) { + await trx("logs").whereIn("id", logIdsToDelete).del(); + } await trx("snapshots").truncate(); await saveSnapshots(trx, snapshots); }); @@ -194,6 +198,9 @@ async function logResults(results: Result[]) { export function getConnection(context: string): Knex { if (_connection) { + if (context !== _context) { + throw new Error(`Sqlite connection already established with context ${ _context } and now requesting ${ context }`); + } return _connection; } if (!context) { @@ -206,6 +213,7 @@ export function getConnection(context: string): Knex { if (!fs.existsSync(fullPathToDir)){ fs.mkdirSync(fullPathToDir); } + _context = context; _connection = knex({ client: 'sqlite3', connection: {