-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drone e2e backend populate with data
- Loading branch information
Showing
5 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
opencti-platform/opencti-graphql/script/script-wait-for-api.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import fetch from 'node-fetch'; | ||
import conf, { logApp } from '../src/config/conf'; | ||
|
||
const API_URI = `http://localhost:${conf.get('app:port')}`; | ||
|
||
const MAX_ATTEMPTS = 20; | ||
const DELAY_BETWEEN_ATTEMPTS = 5000; | ||
|
||
const checkApiAvailability = async () => { | ||
try { | ||
await fetch(`${API_URI}/health`, {}); | ||
return true; | ||
} catch (e) { | ||
logApp.info('[WAIT-FOR-API] API unavailable'); | ||
return false; | ||
} | ||
}; | ||
|
||
const waitForApi = async () => { | ||
const delay = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); }); | ||
logApp.info('[WAIT-FOR-API] Start waiting for API'); | ||
|
||
let available = false; | ||
let attempt = 0; | ||
while (!available && attempt < MAX_ATTEMPTS) { | ||
if (attempt > 0) { | ||
await delay(DELAY_BETWEEN_ATTEMPTS); | ||
} | ||
attempt += 1; | ||
available = await checkApiAvailability(); | ||
} | ||
if (!available) { | ||
logApp.error('[WAIT-FOR-API] API not reachable'); | ||
process.exit(1); | ||
} | ||
logApp.info('[WAIT-FOR-API] Success - API reachable'); | ||
}; | ||
|
||
// noinspection JSIgnoredPromiseFromCall | ||
waitForApi(); |