-
Notifications
You must be signed in to change notification settings - Fork 9
/
warmup.ts
51 lines (47 loc) · 1.96 KB
/
warmup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { generateApolloClient } from '@deep-foundation/hasura/client.js';
import { DeepClient } from "./imports/client.js";
import axios from 'axios';
import Debug from 'debug';
import { serializeError } from 'serialize-error';
const debug = Debug('deeplinks:warmup');
const apolloClient = generateApolloClient({
path: `${process.env.DEEPLINKS_HASURA_PATH}/v1/graphql`,
ssl: !!+process.env.DEEPLINKS_HASURA_SSL,
secret: process.env.DEEPLINKS_HASURA_SECRET,
});
const deep = new DeepClient({ apolloClient });
export const checkSystemStatus = async (): Promise<{ result?: any; error?: any }> => {
try {
const status = await axios.post(`http://localhost:3006/gql`, { "query": "{ healthz { status } }" }, { validateStatus: status => true, timeout: 7000 });
// console.log('system status result', JSON.stringify(status?.data));
return { result: status?.data?.data?.healthz?.[0].status };
} catch (e) {
// console.log('system status error', e);
const serializedError = serializeError(e);
return { error: serializedError };
}
};
(async () => {
let systemIsReady = false;
while(!systemIsReady) {
systemIsReady = (await checkSystemStatus()).result === 'ok';
}
const stringClientHandlerId = await deep.id("@deep-foundation/deepcase", "stringClientHandler");
const stringClientHandler = (await deep.select(stringClientHandlerId));
// console.log(JSON.stringify(stringClientHandler, null, 2));
let jsx = stringClientHandler?.data?.[0]?.value?.value;
// console.log(jsx);
if (jsx) {
var lastChar = jsx.substr(jsx.length - 1);
// console.log('lastChar', lastChar);
if (lastChar == '}') {
jsx += " ";
} else {
jsx = jsx.trim();
}
await deep.update({ link_id: stringClientHandlerId }, { value: jsx }, { table: `strings` });
console.log('JavaScript Docker Isolation Provider startup triggered.');
} else {
console.log('Link value to trigger JavaScript Docker Isolation Provider startup is not found.');
}
})();