@kumologica/sdk 3.6.4-beta5 → 3.6.4-beta7
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/cli/commands/run.js +65 -24
- package/package.json +4 -4
package/cli/commands/run.js
CHANGED
|
@@ -28,6 +28,7 @@ const { codegen } = require("@kumologica/builder");
|
|
|
28
28
|
const { TaskServer} = require("../../src/server/TaskServer");
|
|
29
29
|
//const { DesignerServer } = require("../../src/server/DesignerServer");
|
|
30
30
|
const { logError, logNotice, logInfo, logFatal } = require("../utils/logger");
|
|
31
|
+
const { log } = require("console");
|
|
31
32
|
|
|
32
33
|
exports.command = "run [project_directory]";
|
|
33
34
|
exports.desc = `Start a local HTTP server to execute task and then stops HTTP server and exit.`;
|
|
@@ -54,6 +55,13 @@ exports.builder = (yargs) => {
|
|
|
54
55
|
alias: "t",
|
|
55
56
|
nargs: 1,
|
|
56
57
|
});
|
|
58
|
+
yargs.option(`taskTimeout`, {
|
|
59
|
+
describe: "The timeout in seconds for task execution, default 1800 seconds (30 minutes).",
|
|
60
|
+
type: "number",
|
|
61
|
+
alias: "o",
|
|
62
|
+
default: 1800,
|
|
63
|
+
nargs: 1,
|
|
64
|
+
});
|
|
57
65
|
yargs.option(`args`, {
|
|
58
66
|
describe: "The list of arguments, either '-a one two three' or '-a one -a two -a three' ",
|
|
59
67
|
type: "array",
|
|
@@ -61,19 +69,28 @@ exports.builder = (yargs) => {
|
|
|
61
69
|
});
|
|
62
70
|
};
|
|
63
71
|
|
|
64
|
-
exports.handler = async ({ project_directory, loglevel, port, taskName, args }) => {
|
|
72
|
+
exports.handler = async ({ project_directory, loglevel, port, taskName, taskTimeout, args }) => {
|
|
65
73
|
logNotice(`Starting HTTP Server...`);
|
|
66
74
|
let projectDirectory = project_directory || process.cwd();
|
|
67
75
|
// project_directory can point to a directory or a flow, so lets make sure that first the directory exists
|
|
68
76
|
let absProjectDirectory;
|
|
69
77
|
let exitCode = 1;
|
|
78
|
+
// Timeout in ms (default 10 minutes); make configurable via env or param if needed
|
|
79
|
+
const TIMEOUT_MS =
|
|
80
|
+
(typeof taskTimeout !== 'undefined' ? 1000 * taskTimeout :
|
|
81
|
+
process.env.TIMEOUT_MS ? Number(process.env.TIMEOUT_MS) :
|
|
82
|
+
30 * 60 * 1000); // 30 minutes default in ms
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
logInfo(`TIMEOUT_MS: ${TIMEOUT_MS} ms`);
|
|
70
86
|
try {
|
|
71
87
|
absProjectDirectory = fs.realpathSync(projectDirectory);
|
|
72
88
|
} catch (err) {
|
|
73
89
|
logFatal(`Project not found: ${projectDirectory}`);
|
|
74
90
|
process.exit(exitCode);
|
|
75
91
|
}
|
|
76
|
-
|
|
92
|
+
|
|
93
|
+
let server;
|
|
77
94
|
try {
|
|
78
95
|
// Resolve the path to the flow path
|
|
79
96
|
const [projectFlowDirname, projectFlowFullPath] = resolveProjectFlowPath(absProjectDirectory);
|
|
@@ -87,35 +104,59 @@ exports.handler = async ({ project_directory, loglevel, port, taskName, args })
|
|
|
87
104
|
};
|
|
88
105
|
|
|
89
106
|
// Start a server
|
|
90
|
-
|
|
107
|
+
server = new TaskServer(projectFlowFullPath, cliParams);
|
|
91
108
|
|
|
92
109
|
await server.listen();
|
|
93
110
|
|
|
94
|
-
const
|
|
95
|
-
const req = {
|
|
96
|
-
method: 'POST',
|
|
97
|
-
headers: {
|
|
98
|
-
},
|
|
99
|
-
body: JSON.stringify({args: args})
|
|
100
|
-
};
|
|
111
|
+
const got = require('got');
|
|
101
112
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
const tName = taskName || process.env.taskName;
|
|
114
|
+
const url = `http://127.0.0.1:${port || 1880}/__task__/${tName}`;
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
const response = await got(url, {
|
|
118
|
+
method: 'POST',
|
|
119
|
+
headers: {
|
|
120
|
+
// Add any specific headers here if needed (e.g., 'Content-Type': 'application/json')
|
|
121
|
+
},
|
|
122
|
+
json: { args: args }, // Automatically stringifies to JSON and sets Content-Type
|
|
123
|
+
timeout: { request: TIMEOUT_MS } // Full request timeout (headers + body)
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Log success and response details
|
|
127
|
+
logInfo(`Request succeeded!`);
|
|
128
|
+
logInfo(`Status: ${response.statusCode}`);
|
|
129
|
+
logInfo(`Response body: ${response.body}`); // Assuming JSON response; parse if needed via response.json
|
|
130
|
+
|
|
131
|
+
exitCode = 0;
|
|
132
|
+
|
|
133
|
+
} catch (error) {
|
|
134
|
+
// Log failure details
|
|
135
|
+
logFatal(`Task Error: ${error.message}`);
|
|
136
|
+
|
|
137
|
+
// if (error.response) {
|
|
138
|
+
// logFatal('Status:', error.response.statusCode);
|
|
139
|
+
// logFatal('Response body:', error.response.body);
|
|
140
|
+
// }
|
|
141
|
+
if (error.code === 'ETIMEDOUT') {
|
|
142
|
+
logFatal(`Timeout exceeded (${TIMEOUT_MS / 1000}s)`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch (error) {
|
|
146
|
+
logFatal(`Task failed!`);
|
|
147
|
+
logFatal(`Error: ${error.message}`);
|
|
148
|
+
}
|
|
110
149
|
|
|
150
|
+
try {
|
|
151
|
+
if (server) {
|
|
111
152
|
await server.stop();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
} catch (e) {
|
|
117
|
-
logFatal(e.message);
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
logError('Error stopping server:', error.message);
|
|
118
156
|
}
|
|
157
|
+
logInfo('HTTP Server stopped.');
|
|
158
|
+
|
|
159
|
+
process.exit(exitCode); // Error exit
|
|
119
160
|
};
|
|
120
161
|
|
|
121
162
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumologica/sdk",
|
|
3
|
-
"version": "3.6.4-
|
|
3
|
+
"version": "3.6.4-beta7",
|
|
4
4
|
"productName": "Kumologica Designer",
|
|
5
5
|
"copyright": "Copyright 2020 Kumologica Pty Ltd, All Rights Reserved.",
|
|
6
6
|
"author": "Kumologica Pty Ltd <contact@kumologica.com>",
|
|
@@ -83,9 +83,9 @@
|
|
|
83
83
|
"@aws-sdk/credential-providers": "^3.556.0",
|
|
84
84
|
"@aws-sdk/lib-dynamodb": "^3.549.0",
|
|
85
85
|
"@electron/remote": "^2.0.8",
|
|
86
|
-
"@kumologica/builder": "3.6.4-
|
|
87
|
-
"@kumologica/devkit": "3.6.4-
|
|
88
|
-
"@kumologica/runtime": "3.6.4-
|
|
86
|
+
"@kumologica/builder": "3.6.4-beta7",
|
|
87
|
+
"@kumologica/devkit": "3.6.4-beta7",
|
|
88
|
+
"@kumologica/runtime": "3.6.4-beta7",
|
|
89
89
|
"ajv": "8.10.0",
|
|
90
90
|
"archive-type": "^4.0.0",
|
|
91
91
|
"basic-auth": "2.0.1",
|