@geode/opengeodeweb-front 10.29.0-rc.3 → 10.29.0-rc.4
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/app/utils/local/microservices.js +61 -32
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ import { executablePath } from "./path.js";
|
|
|
13
13
|
|
|
14
14
|
const MILLISECONDS_PER_SECOND = 1000;
|
|
15
15
|
const DEFAULT_TIMEOUT_SECONDS = 45;
|
|
16
|
+
const MAX_PORT_RETRIES = 1;
|
|
16
17
|
|
|
17
18
|
async function runScript(
|
|
18
19
|
execPath,
|
|
@@ -51,7 +52,11 @@ async function runScript(
|
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
function isPortInUseError(errorMessage) {
|
|
56
|
+
return /EADDRINUSE|address already in use|port already in use/iu.test(errorMessage);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function runBack(execName, execPath, args = {}, attempts = 0) {
|
|
55
60
|
const { projectFolderPath } = args;
|
|
56
61
|
if (!projectFolderPath) {
|
|
57
62
|
throw new Error("projectFolderPath is required");
|
|
@@ -60,44 +65,68 @@ async function runBack(execName, execPath, args = {}) {
|
|
|
60
65
|
if (!uploadFolderPath) {
|
|
61
66
|
uploadFolderPath = path.join(projectFolderPath, "uploads");
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
try {
|
|
69
|
+
const port = await getAvailablePort();
|
|
70
|
+
const backArgs = [
|
|
71
|
+
"--port",
|
|
72
|
+
String(port),
|
|
73
|
+
"--project_folder_path",
|
|
74
|
+
projectFolderPath,
|
|
75
|
+
"--upload_folder_path",
|
|
76
|
+
uploadFolderPath,
|
|
77
|
+
"--allowed_origins",
|
|
78
|
+
"http://localhost:*",
|
|
79
|
+
"--timeout",
|
|
80
|
+
"0",
|
|
81
|
+
];
|
|
82
|
+
if (process.env.NODE_ENV === "development" || !process.env.NODE_ENV) {
|
|
83
|
+
backArgs.push("--debug");
|
|
84
|
+
}
|
|
85
|
+
console.log("runBack", execPath, execName, backArgs);
|
|
86
|
+
await runScript(execPath, execName, backArgs, "Serving Flask app");
|
|
87
|
+
return port;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (!isPortInUseError(error)) {
|
|
90
|
+
console.log("runBack error", error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
if (attempts <= MAX_PORT_RETRIES) {
|
|
94
|
+
console.log("Retrying runBack on conflicting port", port);
|
|
95
|
+
const port = await runBack(execName, execPath, args, attempts + 1);
|
|
96
|
+
return port;
|
|
97
|
+
}
|
|
78
98
|
}
|
|
79
|
-
console.log("runBack", execPath, execName, backArgs);
|
|
80
|
-
await runScript(execPath, execName, backArgs, "Serving Flask app");
|
|
81
|
-
return port;
|
|
82
99
|
}
|
|
83
100
|
|
|
84
|
-
async function runViewer(execName, execPath, args = {}) {
|
|
101
|
+
async function runViewer(execName, execPath, args = {}, attempts = 0) {
|
|
85
102
|
const { projectFolderPath } = args;
|
|
86
103
|
if (!projectFolderPath) {
|
|
87
104
|
throw new Error("projectFolderPath is required");
|
|
88
105
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
try {
|
|
107
|
+
const port = await getAvailablePort();
|
|
108
|
+
const viewerArgs = [
|
|
109
|
+
"--port",
|
|
110
|
+
String(port),
|
|
111
|
+
"--project_folder_path",
|
|
112
|
+
projectFolderPath,
|
|
113
|
+
"--timeout",
|
|
114
|
+
"0",
|
|
115
|
+
];
|
|
116
|
+
console.log("runViewer", execPath, execName, viewerArgs);
|
|
117
|
+
await runScript(execPath, execName, viewerArgs, "Starting factory");
|
|
118
|
+
return port;
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (!isPortInUseError(error)) {
|
|
121
|
+
console.log("runBack error", error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
if (attempts <= MAX_PORT_RETRIES) {
|
|
125
|
+
console.log("Retrying runViewer on conflicting port", port);
|
|
126
|
+
const port = await runViewer(execName, execPath, args, attempts + 1);
|
|
127
|
+
return port;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
101
130
|
}
|
|
102
131
|
|
|
103
132
|
function addMicroserviceMetadatas(projectFolderPath, serviceObj) {
|
package/package.json
CHANGED