@intuned/runtime-dev 0.1.0-test.9 → 1.0.0-udas.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/.babelrc +0 -2
- package/InterfaceTemplate/index.playwright.ts +5 -0
- package/InterfaceTemplate/utils.ts +39 -0
- package/WebTemplate/api.ts +90 -92
- package/WebTemplate/controllers/async.ts +52 -48
- package/WebTemplate/controllers/authSessions/check.ts +4 -5
- package/WebTemplate/controllers/authSessions/create.ts +6 -8
- package/WebTemplate/controllers/authSessions/resumeOperation.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +13 -8
- package/WebTemplate/index.playwright.ts +32 -42
- package/WebTemplate/jobs.ts +13 -2
- package/WebTemplate/utils.ts +48 -1
- package/bin/intuned-ts-check +1 -1
- package/dist/commands/api/run.js +7 -5
- package/dist/commands/auth-sessions/run-check.js +9 -3
- package/dist/commands/auth-sessions/run-create.js +11 -6
- package/dist/commands/build.js +17 -12
- package/dist/commands/common/tsNodeImport.d.ts +1 -0
- package/dist/commands/common/tsNodeImport.js +20 -0
- package/dist/commands/common/utils/settings.js +5 -5
- package/dist/commands/common/utils/template.d.ts +2 -0
- package/dist/commands/common/utils/{webTemplate.js → template.js} +7 -7
- package/dist/commands/interface/run.d.ts +1 -2
- package/dist/commands/interface/run.js +147 -110
- package/dist/commands/ts-check.js +9 -7
- package/dist/common/formatZodError.d.ts +2 -0
- package/dist/common/formatZodError.js +18 -0
- package/dist/common/getPlaywrightConstructs.js +6 -2
- package/dist/common/runApi/errors.d.ts +8 -3
- package/dist/common/runApi/errors.js +26 -3
- package/dist/common/runApi/index.d.ts +1 -1
- package/dist/common/runApi/index.js +36 -65
- package/dist/common/runApi/types.d.ts +287 -71
- package/dist/common/runApi/types.js +29 -5
- package/dist/runtime/executionHelpers.test.js +6 -6
- package/package.json +3 -3
- package/tsconfig.json +1 -2
- package/InterfaceTemplate/index.ts +0 -1
- package/Intuned.json +0 -5
- package/api/authed.ts +0 -12
- package/api/test.ts +0 -3
- package/api/test2.ts +0 -22
- package/auth-sessions/check.ts +0 -9
- package/auth-sessions/create.ts +0 -32
- package/authSessions +0 -1
- package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
- package/dist/commands/common/getDefaultExportFromFile.js +0 -17
- package/dist/commands/common/utils/webTemplate.d.ts +0 -1
- package/output.txt +0 -39
- package/preserve-dynamic-imports.js +0 -16
- package/testing +0 -0
package/.babelrc
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export async function importModule(path: string) {
|
|
2
|
+
const [folderName, ...functionNameParts] = path.split("/");
|
|
3
|
+
const functionNameDepth = functionNameParts.length;
|
|
4
|
+
|
|
5
|
+
// string literals should be inline
|
|
6
|
+
// currently we support only 5 levels of depth
|
|
7
|
+
// rollup dynamic import does not support multiple levels of dynamic imports so we need to specify the possible paths explicitly
|
|
8
|
+
let imported: any = undefined;
|
|
9
|
+
switch (functionNameDepth) {
|
|
10
|
+
case 1:
|
|
11
|
+
imported = await import(`./${folderName}/${functionNameParts[0]}.ts`);
|
|
12
|
+
break;
|
|
13
|
+
case 2:
|
|
14
|
+
imported = await import(
|
|
15
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}.ts`
|
|
16
|
+
);
|
|
17
|
+
break;
|
|
18
|
+
case 3:
|
|
19
|
+
imported = await import(
|
|
20
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`
|
|
21
|
+
);
|
|
22
|
+
break;
|
|
23
|
+
case 4:
|
|
24
|
+
imported = await import(
|
|
25
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`
|
|
26
|
+
);
|
|
27
|
+
break;
|
|
28
|
+
case 5:
|
|
29
|
+
imported = await import(
|
|
30
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`
|
|
31
|
+
);
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
throw new Error(
|
|
35
|
+
"intuned supports maximum 5 levels of depth in the api folder"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return imported;
|
|
39
|
+
}
|
package/WebTemplate/api.ts
CHANGED
|
@@ -33,109 +33,107 @@ import {
|
|
|
33
33
|
} from "./headers";
|
|
34
34
|
import { FEATURES } from "./features";
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
app.get(
|
|
58
|
-
"/api/protected/health",
|
|
59
|
-
accessKeyValidatorMiddleware,
|
|
60
|
-
async (req, res) => {
|
|
61
|
-
res.status(200).json({ status: "ok" });
|
|
62
|
-
}
|
|
63
|
-
);
|
|
36
|
+
if (!isJobRunMachine()) {
|
|
37
|
+
app.use((req, _, next) => {
|
|
38
|
+
const runId = req.headers[RUN_ID_HEADER] as string;
|
|
39
|
+
const jobId = req.headers[JOB_ID_HEADER] as string;
|
|
40
|
+
const jobRunId = req.headers[JOB_RUN_ID_HEADER] as string;
|
|
41
|
+
const queueId = req.headers[QUEUE_ID_HEADER] as string;
|
|
42
|
+
const proxy = req?.body?.proxy
|
|
43
|
+
? (proxyToUrl(req.body.proxy as ProxyConfig) as string)
|
|
44
|
+
: undefined;
|
|
45
|
+
const contextData = {
|
|
46
|
+
runId: runId ?? "",
|
|
47
|
+
jobId,
|
|
48
|
+
jobRunId,
|
|
49
|
+
queueId,
|
|
50
|
+
proxy,
|
|
51
|
+
...(req?.body?.executionContext ?? {}),
|
|
52
|
+
};
|
|
53
|
+
runWithContext(contextData, next);
|
|
54
|
+
});
|
|
64
55
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
app.get(
|
|
57
|
+
"/api/protected/health",
|
|
58
|
+
accessKeyValidatorMiddleware,
|
|
59
|
+
async (req, res) => {
|
|
60
|
+
res.status(200).json({ status: "ok" });
|
|
61
|
+
}
|
|
62
|
+
);
|
|
70
63
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
app.post(
|
|
65
|
+
"/api/auth-session/create",
|
|
66
|
+
accessKeyValidatorMiddleware,
|
|
67
|
+
errorRetryMiddleware(createAuthSessionController)
|
|
68
|
+
);
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
70
|
+
app.post(
|
|
71
|
+
"/api/auth-session-async/create",
|
|
72
|
+
accessKeyValidatorMiddleware,
|
|
73
|
+
errorRetryMiddleware(createAuthSessionAsyncController)
|
|
74
|
+
);
|
|
82
75
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
76
|
+
app.post(
|
|
77
|
+
"/api/auth-session/check",
|
|
78
|
+
accessKeyValidatorMiddleware,
|
|
79
|
+
errorRetryMiddleware(checkAuthSessionController)
|
|
80
|
+
);
|
|
88
81
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
app.post(
|
|
83
|
+
"/api/auth-session-async/check",
|
|
84
|
+
accessKeyValidatorMiddleware,
|
|
85
|
+
errorRetryMiddleware(checkAuthSessionAsyncController)
|
|
86
|
+
);
|
|
94
87
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
app.post(
|
|
89
|
+
"/api/auth-session/kill",
|
|
90
|
+
accessKeyValidatorMiddleware,
|
|
91
|
+
errorRetryMiddleware(killAuthSessionOperationController)
|
|
92
|
+
);
|
|
100
93
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
app.post(
|
|
95
|
+
"/api/auth-session/resume",
|
|
96
|
+
accessKeyValidatorMiddleware,
|
|
97
|
+
errorRetryMiddleware(resumeAuthSessionOperationController)
|
|
98
|
+
);
|
|
106
99
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
app.post(
|
|
101
|
+
"/api/auth-session-async/resume",
|
|
102
|
+
accessKeyValidatorMiddleware,
|
|
103
|
+
errorRetryMiddleware(resumeAuthSessionOperationAsyncController)
|
|
104
|
+
);
|
|
112
105
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
app.post(
|
|
107
|
+
"/api/run/*",
|
|
108
|
+
accessKeyValidatorMiddleware,
|
|
109
|
+
errorRetryMiddleware(runApiController)
|
|
110
|
+
);
|
|
118
111
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
app.post(
|
|
113
|
+
"/api/run-async/start/*",
|
|
114
|
+
accessKeyValidatorMiddleware,
|
|
115
|
+
errorRetryMiddleware(runApiAsyncController) // todo: this probably needs changing
|
|
116
|
+
);
|
|
124
117
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
app.get(
|
|
119
|
+
"/api/run-async/count",
|
|
120
|
+
accessKeyValidatorMiddleware,
|
|
121
|
+
getActiveAsyncEndpointController
|
|
122
|
+
);
|
|
130
123
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
124
|
+
app.post(
|
|
125
|
+
"/api/trace/upload/:runId",
|
|
126
|
+
accessKeyValidatorMiddleware,
|
|
127
|
+
uploadTraceController
|
|
128
|
+
);
|
|
137
129
|
|
|
138
|
-
app.
|
|
139
|
-
|
|
140
|
-
|
|
130
|
+
app.post(
|
|
131
|
+
"/api/trace/delete/:runId",
|
|
132
|
+
accessKeyValidatorMiddleware,
|
|
133
|
+
deleteTraceController
|
|
134
|
+
);
|
|
141
135
|
}
|
|
136
|
+
|
|
137
|
+
app.get("/api/features", accessKeyValidatorMiddleware, async (_, res) => {
|
|
138
|
+
res.status(200).json({ features: FEATURES });
|
|
139
|
+
});
|
|
@@ -40,59 +40,63 @@ export async function runEndpointAsync<_Parameters extends any[], _Result>(
|
|
|
40
40
|
} catch (e: any) {
|
|
41
41
|
console.error(`Error running ${requestId} in async mode:`, e);
|
|
42
42
|
({ status, body } = getErrorResponse(e));
|
|
43
|
-
} finally {
|
|
44
|
-
AsyncRunEndpointController.removeRequest(taskToken);
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
// report result
|
|
48
|
-
console.log("Reporting result for", requestId);
|
|
49
45
|
try {
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
46
|
+
// report result
|
|
47
|
+
console.log("Reporting result for", requestId);
|
|
48
|
+
try {
|
|
49
|
+
// `retry` will keep retrying any errors unless they are thrown through calling `bail`
|
|
50
|
+
await retry(
|
|
51
|
+
async (bail: (e: Error) => void) => {
|
|
52
|
+
const response = await callBackendFunctionWithToken(
|
|
53
|
+
"run/reportResult",
|
|
54
|
+
{
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: {
|
|
57
|
+
"Content-Type": "application/json",
|
|
58
|
+
"fly-instance-id": process.env.FLY_ALLOC_ID ?? "",
|
|
59
|
+
},
|
|
60
|
+
body: JSON.stringify({
|
|
61
|
+
status,
|
|
62
|
+
body,
|
|
63
|
+
startTime,
|
|
64
|
+
taskToken,
|
|
65
|
+
}),
|
|
66
|
+
}
|
|
67
|
+
).catch((e) => {
|
|
68
|
+
const message = `Reporting result failed for ${requestId}, error: ${e.message}`;
|
|
69
|
+
console.error(message);
|
|
70
|
+
throw e;
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
// Do not retry unauthenticated, forbidden, not found or too large responses
|
|
74
|
+
if ([401, 403, 404, 413].includes(response.status)) {
|
|
75
|
+
const message = `Reporting result failed for ${requestId} (non-retryable), status ${response.status}`;
|
|
76
|
+
console.error(message);
|
|
77
|
+
bail(new Error(message));
|
|
78
|
+
}
|
|
79
|
+
// retry other errors (such as 502)
|
|
80
|
+
const message = `Reporting result failed for ${requestId}, status ${response.status}`;
|
|
81
|
+
console.error(message);
|
|
82
|
+
throw new Error(message);
|
|
77
83
|
}
|
|
78
|
-
// retry other errors (such as 502)
|
|
79
|
-
throw new Error(
|
|
80
|
-
`Reporting result failed for ${requestId}, status ${response.status}`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
return response;
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
retries: 5,
|
|
89
|
+
factor: 2,
|
|
90
|
+
maxTimeout: 1000 * 60, // 1 minute
|
|
91
|
+
minTimeout: 1000 * 5, // 5 seconds
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
console.log("Reported result for", requestId);
|
|
95
|
+
} catch (e: any) {
|
|
96
|
+
// ignore
|
|
97
|
+
}
|
|
98
|
+
} finally {
|
|
99
|
+
AsyncRunEndpointController.removeRequest(taskToken);
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
await ShutdownController.instance.checkForShutdown();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readJSON } from "fs-extra";
|
|
2
2
|
import { isHeadless } from "../../utils";
|
|
3
3
|
import { runApi } from "@intuned/runtime/dist/common/runApi";
|
|
4
|
+
import { importModule } from "../../utils";
|
|
4
5
|
|
|
5
6
|
export async function checkAuthSession({
|
|
6
7
|
proxy,
|
|
@@ -35,7 +36,7 @@ export async function checkAuthSession({
|
|
|
35
36
|
name: "auth-sessions/check",
|
|
36
37
|
},
|
|
37
38
|
runOptions: {
|
|
38
|
-
environment: "
|
|
39
|
+
environment: "standalone",
|
|
39
40
|
headless: isHeadless(),
|
|
40
41
|
proxy,
|
|
41
42
|
},
|
|
@@ -46,12 +47,10 @@ export async function checkAuthSession({
|
|
|
46
47
|
},
|
|
47
48
|
runCheck: false,
|
|
48
49
|
},
|
|
50
|
+
importFunction: importModule,
|
|
49
51
|
});
|
|
50
52
|
if (result.isErr()) {
|
|
51
|
-
return
|
|
52
|
-
status: 500,
|
|
53
|
-
body: result.error,
|
|
54
|
-
};
|
|
53
|
+
return result.error.apiResponse;
|
|
55
54
|
}
|
|
56
55
|
return {
|
|
57
56
|
status: 200,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { authSessionsContextsStore } from "./store";
|
|
2
|
-
import { getTraceFilePath, isHeadless } from "../../utils";
|
|
2
|
+
import { getTraceFilePath, isHeadless, importModule } from "../../utils";
|
|
3
3
|
import * as fs from "fs-extra";
|
|
4
4
|
import { runApiGenerator } from "@intuned/runtime/dist/common/runApi";
|
|
5
5
|
import type { RequestMoreInfoDetails } from "@intuned/runtime/dist/runtime";
|
|
@@ -54,7 +54,7 @@ export async function createAuthSession({
|
|
|
54
54
|
>({
|
|
55
55
|
automationFunction: {
|
|
56
56
|
name: "auth-sessions/create",
|
|
57
|
-
params: parameters
|
|
57
|
+
params: parameters,
|
|
58
58
|
},
|
|
59
59
|
tracing: saveTrace
|
|
60
60
|
? {
|
|
@@ -63,24 +63,22 @@ export async function createAuthSession({
|
|
|
63
63
|
}
|
|
64
64
|
: { enabled: false },
|
|
65
65
|
runOptions: {
|
|
66
|
-
environment: "
|
|
66
|
+
environment: "standalone",
|
|
67
67
|
headless,
|
|
68
68
|
proxy,
|
|
69
69
|
},
|
|
70
70
|
abortSignal: abortController.signal,
|
|
71
71
|
retrieveSession: true,
|
|
72
|
+
importFunction: importModule,
|
|
72
73
|
});
|
|
73
74
|
|
|
74
75
|
const result = await createGenerator.next();
|
|
75
76
|
|
|
76
|
-
if (result.done) {
|
|
77
|
+
if (result.done === true) {
|
|
77
78
|
const r = result.value;
|
|
78
79
|
|
|
79
80
|
if (r.isErr()) {
|
|
80
|
-
return
|
|
81
|
-
status: 500,
|
|
82
|
-
body: r.error,
|
|
83
|
-
};
|
|
81
|
+
return r.error.apiResponse;
|
|
84
82
|
}
|
|
85
83
|
|
|
86
84
|
return {
|
|
@@ -33,7 +33,7 @@ export async function resumeAuthSessionOperation({
|
|
|
33
33
|
|
|
34
34
|
const result = await operation.generator.next(input);
|
|
35
35
|
|
|
36
|
-
if (result.done) {
|
|
36
|
+
if (result.done === true) {
|
|
37
37
|
authSessionsContextsStore.delete(operationId);
|
|
38
38
|
if (result.value.isErr()) {
|
|
39
39
|
return result.value.error.apiResponse;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getTraceFilePath,
|
|
3
|
+
importModule,
|
|
4
|
+
waitWithExtendableTimeout,
|
|
5
|
+
} from "../../utils";
|
|
2
6
|
import * as fs from "fs-extra";
|
|
3
7
|
import { getExecutionContext } from "@intuned/runtime";
|
|
4
8
|
import { backendFunctionsTokenManager } from "@intuned/runtime/dist/common/jwtTokenManager";
|
|
@@ -61,23 +65,24 @@ export async function runApi({
|
|
|
61
65
|
|
|
62
66
|
const abortController = new AbortController();
|
|
63
67
|
|
|
68
|
+
backendFunctionsTokenManager.token = functionsToken;
|
|
64
69
|
const resultWithTimeout = await waitWithExtendableTimeout({
|
|
65
70
|
promise: runApiInternal({
|
|
66
71
|
automationFunction: {
|
|
67
72
|
name: `api/${functionName}`,
|
|
68
|
-
params
|
|
73
|
+
params,
|
|
69
74
|
},
|
|
70
|
-
auth:
|
|
71
|
-
?
|
|
72
|
-
: {
|
|
75
|
+
auth: isAuthSessionEnabled
|
|
76
|
+
? {
|
|
73
77
|
session: {
|
|
74
78
|
type: "state",
|
|
75
79
|
state: session,
|
|
76
80
|
},
|
|
77
81
|
runCheck: isAuthSessionEnabled,
|
|
78
|
-
}
|
|
82
|
+
}
|
|
83
|
+
: undefined,
|
|
79
84
|
runOptions: {
|
|
80
|
-
environment: "
|
|
85
|
+
environment: "standalone",
|
|
81
86
|
headless,
|
|
82
87
|
proxy,
|
|
83
88
|
},
|
|
@@ -87,8 +92,8 @@ export async function runApi({
|
|
|
87
92
|
filePath: getTraceFilePath(runId, attemptNumber),
|
|
88
93
|
}
|
|
89
94
|
: { enabled: false },
|
|
90
|
-
functionsToken,
|
|
91
95
|
abortSignal: abortController.signal,
|
|
96
|
+
importFunction: importModule,
|
|
92
97
|
}),
|
|
93
98
|
initialTimeout: requestTimeout,
|
|
94
99
|
abortController,
|
|
@@ -6,52 +6,42 @@ import { getExecutionContext } from "@intuned/runtime";
|
|
|
6
6
|
import { app } from "./app";
|
|
7
7
|
import { RUN_ID_HEADER } from "./headers";
|
|
8
8
|
import { ShutdownController } from "./shutdown";
|
|
9
|
-
import { registerApiEndpoints } from "./api";
|
|
10
|
-
import { runJobsLoop } from "./jobs";
|
|
11
|
-
import { isJobRunMachine } from "./utils";
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
|
|
12
|
+
initializeAppInsights();
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
res.on("finish", () => {
|
|
23
|
-
console.log("finished", req.headers[RUN_ID_HEADER]);
|
|
24
|
-
void ShutdownController.instance.checkForShutdown();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
next();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
registerApiEndpoints();
|
|
31
|
-
if (isJobRunMachine()) {
|
|
32
|
-
console.log("Running in job v3 mode");
|
|
33
|
-
void runJobsLoop();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const server = app.listen(port, () => {
|
|
37
|
-
// when deployed on flyio, the server will be turned on and
|
|
38
|
-
// will shutdown after the specified time in TIME_TO_SHUTDOWN env variable
|
|
39
|
-
ShutdownController.initialize(server);
|
|
14
|
+
app.use((req, res, next) => {
|
|
15
|
+
// Cleanup after the response is sent
|
|
16
|
+
res.on("finish", () => {
|
|
17
|
+
console.log("finished", req.headers[RUN_ID_HEADER]);
|
|
40
18
|
void ShutdownController.instance.checkForShutdown();
|
|
41
|
-
console.log(`Server is running on port ${port}`);
|
|
42
19
|
});
|
|
43
20
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
21
|
+
next();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export * from "./api";
|
|
25
|
+
export * from "./jobs";
|
|
26
|
+
|
|
27
|
+
const server = app.listen(port, () => {
|
|
28
|
+
// when deployed on flyio, the server will be turned on and
|
|
29
|
+
// will shutdown after the specified time in TIME_TO_SHUTDOWN env variable
|
|
30
|
+
ShutdownController.initialize(server);
|
|
31
|
+
void ShutdownController.instance.checkForShutdown();
|
|
32
|
+
console.log(`Server is running on port ${port}`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
process.on("unhandledRejection", (reason, promise) => {
|
|
36
|
+
const telemetryClient = getTelemetryClient();
|
|
37
|
+
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
38
|
+
const context = getExecutionContext();
|
|
39
|
+
telemetryClient?.trackEvent({
|
|
40
|
+
name: "UNHANDLED_REJECTION",
|
|
41
|
+
properties: {
|
|
42
|
+
runId: context?.runId,
|
|
43
|
+
promise,
|
|
44
|
+
reason,
|
|
45
|
+
},
|
|
56
46
|
});
|
|
57
|
-
}
|
|
47
|
+
});
|
package/WebTemplate/jobs.ts
CHANGED
|
@@ -6,7 +6,13 @@ import {
|
|
|
6
6
|
RUN_ID_HEADER,
|
|
7
7
|
SHOULD_SHUTDOWN_HEADER,
|
|
8
8
|
} from "./headers";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getErrorResponse,
|
|
11
|
+
isHeadless,
|
|
12
|
+
isJobRunMachine,
|
|
13
|
+
ProxyConfig,
|
|
14
|
+
proxyToUrl,
|
|
15
|
+
} from "./utils";
|
|
10
16
|
import {
|
|
11
17
|
callBackendFunctionWithToken,
|
|
12
18
|
backendFunctionsTokenManager,
|
|
@@ -26,6 +32,11 @@ type JobPayload = {
|
|
|
26
32
|
traceSignedUrl?: string;
|
|
27
33
|
};
|
|
28
34
|
|
|
35
|
+
if (isJobRunMachine()) {
|
|
36
|
+
console.log("Running in job v3 mode");
|
|
37
|
+
void jobsV3();
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
async function runApiInContext(
|
|
30
41
|
jobPayload: JobPayload
|
|
31
42
|
): Promise<Awaited<ReturnType<typeof runApi>>> {
|
|
@@ -72,7 +83,7 @@ async function runApiInContext(
|
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
85
|
|
|
75
|
-
|
|
86
|
+
async function jobsV3() {
|
|
76
87
|
await reportReady();
|
|
77
88
|
const initialDelay = 1000;
|
|
78
89
|
let delay = initialDelay;
|