()
| 27 | } |
| 28 | |
| 29 | _healthCheck() { |
| 30 | return this.healthCheck().then(data => { |
| 31 | if (data?.date) { |
| 32 | const date = new Date(data.date); |
| 33 | if (Date.now() - date.getTime() > this.maxStaleness) { |
| 34 | throw new Error('Data is stale, disabling quotas'); |
| 35 | } |
| 36 | } |
| 37 | if (!this.enabled) { |
| 38 | this._log.info('Scuba health check passed, enabling quotas'); |
| 39 | } |
| 40 | monitoring.utilizationServiceAvailable.set(1); |
| 41 | this.enabled = true; |
| 42 | }).catch(err => { |
| 43 | if (this.enabled) { |
| 44 | this._log.warn('Scuba health check failed, disabling quotas', { |
| 45 | err: err.name, |
| 46 | description: err.message, |
| 47 | }); |
| 48 | } |
| 49 | monitoring.utilizationServiceAvailable.set(0); |
| 50 | this.enabled = false; |
| 51 | }); |
| 52 | } |
| 53 | |
| 54 | periodicHealthCheck() { |
| 55 | if (this._healthCheckTimer) { |
no test coverage detected