@lokalise/healthcheck-utils 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,19 @@
1
1
  # Healthcheck Utils
2
2
 
3
3
  This package adds common utils that are used to work with healthchecks.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ // this is a part of dependencies
9
+ const store = new HealthcheckResultsStore({
10
+ maxHealthcheckNumber: 10,
11
+ healthCheckResultTtlInMsecs: 40000,
12
+ })
13
+
14
+ const job = new HealthcheckRefreshJob(dependencies, healthcheckList, {
15
+ intervalInMs: 15000,
16
+ })
17
+
18
+ await job.asyncRegister()
19
+ ```
@@ -1,5 +1,5 @@
1
1
  import { AbstractPeriodicJob, type JobExecutionContext, type PeriodicJobDependencies } from '@lokalise/background-jobs-common';
2
- import type { Healthcheck } from './healthchecks.js';
2
+ import type { Healthcheck } from './healthchecks.ts';
3
3
  export type HealthcheckRefreshJobConfig = {
4
4
  intervalInMs?: number;
5
5
  shouldLogExecution?: boolean;
@@ -6,11 +6,9 @@ export type HealthcheckEntry = {
6
6
  };
7
7
  export type HealthcheckResultsStoreParams = {
8
8
  maxHealthcheckNumber: number;
9
- stalenessThresholdInMsecs?: number;
10
9
  healthCheckResultTtlInMsecs?: number;
11
10
  };
12
11
  export declare class HealthcheckResultsStore<SupportedHealthchecks extends string> {
13
- private readonly stalenessThresholdInMsecs;
14
12
  private readonly store;
15
13
  constructor(params: HealthcheckResultsStoreParams);
16
14
  set(healthcheck: SupportedHealthchecks, result: HealthcheckEntry): void;
@@ -1,12 +1,8 @@
1
1
  import { FifoMap } from 'toad-cache';
2
- const DEFAULT_STALENESS_THRESHOLD_IN_MSECS = 30000;
3
- const DEFAULT_HEALTHCHECK_TTL_IN_MSECS = 15000;
2
+ const DEFAULT_HEALTHCHECK_TTL_IN_MSECS = 40000;
4
3
  export class HealthcheckResultsStore {
5
- stalenessThresholdInMsecs;
6
4
  store;
7
5
  constructor(params) {
8
- this.stalenessThresholdInMsecs =
9
- params.stalenessThresholdInMsecs ?? DEFAULT_STALENESS_THRESHOLD_IN_MSECS;
10
6
  this.store = new FifoMap(params.maxHealthcheckNumber, params.healthCheckResultTtlInMsecs ?? DEFAULT_HEALTHCHECK_TTL_IN_MSECS);
11
7
  }
12
8
  set(healthcheck, result) {
@@ -24,12 +20,7 @@ export class HealthcheckResultsStore {
24
20
  if (healthcheckEntry.isSuccessful) {
25
21
  return true;
26
22
  }
27
- if (healthcheckEntry.isSuccessful === false) {
28
- return false;
29
- }
30
- // If we still don't have healthcheck results, check how old the undefined state is
31
- // If it is very stale, assume check is broken and report unhealthy service
32
- return isLessThanMSecsAgo(healthcheckEntry.checkTimestamp, this.stalenessThresholdInMsecs);
23
+ return false;
33
24
  }
34
25
  getHealthcheckLatency(healthcheck) {
35
26
  const healthcheckEntry = this.store.get(healthcheck);
@@ -42,7 +33,4 @@ export class HealthcheckResultsStore {
42
33
  this.store.clear();
43
34
  }
44
35
  }
45
- function isLessThanMSecsAgo(givenDate, deltaInMsecs) {
46
- return Date.now() - givenDate.getTime() < deltaInMsecs;
47
- }
48
36
  //# sourceMappingURL=HealthcheckResultsStore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HealthcheckResultsStore.js","sourceRoot":"","sources":["../src/HealthcheckResultsStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAepC,MAAM,oCAAoC,GAAG,KAAK,CAAA;AAClD,MAAM,gCAAgC,GAAG,KAAK,CAAA;AAE9C,MAAM,OAAO,uBAAuB;IACjB,yBAAyB,CAAQ;IACjC,KAAK,CAA2B;IAEjD,YAAY,MAAqC;QAC/C,IAAI,CAAC,yBAAyB;YAC5B,MAAM,CAAC,yBAAyB,IAAI,oCAAoC,CAAA;QAC1E,IAAI,CAAC,KAAK,GAAG,IAAI,OAAO,CACtB,MAAM,CAAC,oBAAoB,EAC3B,MAAM,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AE,OAAO,EAAE,MAAM,YAAY,CAAA;AAcpC,MAAM,gCAAgC,GAAG,KAAK,CAAA;AAE9C,MAAM,OAAO,uBAAuB;IACjB,KAAK,CAA2B;IAEjD,YAAY,MAAqC;QAC/C,IAAI,CAAC,KAAK,GAAG,IAAI,OAAO,CACtB,MAAM,CAAC,oBAAoB,EAC3B,MAAM,CAAC,2BAA2B,IAAI,gCAAgC,CACvE,CAAA;IACH,CAAC;IAED,GAAG,CAAC,WAAkC,EAAE,MAAwB;QAC9D,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACrC,CAAC;IAED;;OAEG;IACH,oBAAoB,CAAC,WAAkC;QACrD,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QACpD,qEAAqE;QACrE,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,IAAI,gBAAgB,CAAC,YAAY,EAAE,CAAC;YAClC,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;IAED,qBAAqB,CAAC,WAAkC;QACtD,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QACpD,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,OAAO,gBAAgB,CAAC,OAAO,CAAA;IACjC,CAAC;IAED,sBAAsB;QACpB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;CACF"}
@@ -1,5 +1,5 @@
1
1
  import type { Either } from '@lokalise/node-core';
2
- import type { HealthcheckResultsStore } from './HealthcheckResultsStore.js';
2
+ import type { HealthcheckResultsStore } from './HealthcheckResultsStore.ts';
3
3
  export type Healthcheck = {
4
4
  areMetricsEnabled: boolean;
5
5
  instantiateMetrics: () => void;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { Healthcheck, HealthcheckDependencies } from './healthchecks.js';
2
- export { HealthcheckResultsStore } from './HealthcheckResultsStore.js';
3
- export type { HealthcheckResultsStoreParams, HealthcheckEntry } from './HealthcheckResultsStore.js';
4
- export { AbstractHealthcheck } from './healthchecks.js';
5
- export { HealthcheckRefreshJob, type HealthcheckRefreshJobConfig } from './HealthcheckRefreshJob.js';
1
+ export type { Healthcheck, HealthcheckDependencies } from './healthchecks.ts';
2
+ export { HealthcheckResultsStore } from './HealthcheckResultsStore.ts';
3
+ export type { HealthcheckResultsStoreParams, HealthcheckEntry } from './HealthcheckResultsStore.ts';
4
+ export { AbstractHealthcheck } from './healthchecks.ts';
5
+ export { HealthcheckRefreshJob, type HealthcheckRefreshJobConfig } from './HealthcheckRefreshJob.ts';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { HealthcheckResultsStore } from './HealthcheckResultsStore.js';
2
- export { AbstractHealthcheck } from './healthchecks.js';
3
- export { HealthcheckRefreshJob } from './HealthcheckRefreshJob.js';
1
+ export { HealthcheckResultsStore } from "./HealthcheckResultsStore.js";
2
+ export { AbstractHealthcheck } from "./healthchecks.js";
3
+ export { HealthcheckRefreshJob } from "./HealthcheckRefreshJob.js";
4
4
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lokalise/healthcheck-utils",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "files": ["dist/**", "LICENSE.md", "README.md"],
6
6
  "type": "module",
@@ -29,29 +29,29 @@
29
29
  "postversion": "biome check --write package.json"
30
30
  },
31
31
  "dependencies": {
32
- "@lokalise/node-core": "^13.1.0",
32
+ "@lokalise/node-core": "^13.6.0",
33
33
  "@supercharge/promise-pool": "^3.2.0",
34
- "redis-semaphore": "^5.6.1",
34
+ "redis-semaphore": "^5.6.2",
35
35
  "toad-cache": "^3.7.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@lokalise/background-jobs-common": ">=12.0.0",
39
39
  "ioredis": "^5.4.1",
40
40
  "prom-client": "^15.1.3",
41
- "toad-scheduler": "^3.0.1"
41
+ "toad-scheduler": "^3.1.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@biomejs/biome": "^1.9.4",
45
- "@lokalise/background-jobs-common": "^12.0.0",
46
- "@lokalise/biome-config": "^1.5.0",
47
- "@lokalise/node-core": "^13.1.0",
48
- "@lokalise/tsconfig": "^1.0.2",
49
- "@vitest/coverage-v8": "^3.0.7",
50
- "ioredis": "^5.4.1",
45
+ "@lokalise/background-jobs-common": "^12.3.0",
46
+ "@lokalise/biome-config": "^2.0.0",
47
+ "@lokalise/node-core": "^13.6.0",
48
+ "@lokalise/tsconfig": "^1.3.0",
49
+ "@vitest/coverage-v8": "^3.1.2",
50
+ "ioredis": "^5.6.1",
51
51
  "prom-client": "^15.1.3",
52
52
  "rimraf": "^6.0.1",
53
- "toad-scheduler": "^3.0.1",
53
+ "toad-scheduler": "^3.1.0",
54
54
  "typescript": "5.8.3",
55
- "vitest": "^3.0.7"
55
+ "vitest": "^3.1.2"
56
56
  }
57
57
  }