@constructive-io/knative-job-fn 0.2.6 → 0.2.7
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/CHANGELOG.md +4 -0
- package/dist/index.js +72 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.2.7](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-fn@0.2.6...@constructive-io/knative-job-fn@0.2.7) (2025-12-25)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @constructive-io/knative-job-fn
|
|
9
|
+
|
|
6
10
|
## [0.2.6](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-fn@0.2.5...@constructive-io/knative-job-fn@0.2.6) (2025-12-24)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @constructive-io/knative-job-fn
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,46 @@ const body_parser_1 = __importDefault(require("body-parser"));
|
|
|
8
8
|
const node_http_1 = __importDefault(require("node:http"));
|
|
9
9
|
const node_https_1 = __importDefault(require("node:https"));
|
|
10
10
|
const node_url_1 = require("node:url");
|
|
11
|
+
function getHeaders(req) {
|
|
12
|
+
return {
|
|
13
|
+
'x-worker-id': req.get('X-Worker-Id'),
|
|
14
|
+
'x-job-id': req.get('X-Job-Id'),
|
|
15
|
+
'x-database-id': req.get('X-Database-Id'),
|
|
16
|
+
'x-callback-url': req.get('X-Callback-Url')
|
|
17
|
+
};
|
|
18
|
+
}
|
|
11
19
|
const app = (0, express_1.default)();
|
|
12
20
|
app.use(body_parser_1.default.json());
|
|
21
|
+
// Basic request logging for all incoming job invocations.
|
|
22
|
+
app.use((req, res, next) => {
|
|
23
|
+
try {
|
|
24
|
+
// Log only the headers we care about plus a shallow body snapshot
|
|
25
|
+
const headers = getHeaders(req);
|
|
26
|
+
let body;
|
|
27
|
+
if (req.body && typeof req.body === 'object') {
|
|
28
|
+
// Only log top-level keys to avoid exposing sensitive body contents.
|
|
29
|
+
body = { keys: Object.keys(req.body) };
|
|
30
|
+
}
|
|
31
|
+
else if (typeof req.body === 'string') {
|
|
32
|
+
// For string bodies, log only the length.
|
|
33
|
+
body = { length: req.body.length };
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
body = undefined;
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.log('[knative-job-fn] Incoming job request', {
|
|
40
|
+
method: req.method,
|
|
41
|
+
path: req.originalUrl || req.url,
|
|
42
|
+
headers,
|
|
43
|
+
body
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// best-effort logging; never block the request
|
|
48
|
+
}
|
|
49
|
+
next();
|
|
50
|
+
});
|
|
13
51
|
// Echo job headers back on responses for debugging/traceability.
|
|
14
52
|
app.use((req, res, next) => {
|
|
15
53
|
res.set({
|
|
@@ -122,6 +160,13 @@ app.use((req, res, next) => {
|
|
|
122
160
|
if (res.locals.jobCallbackSent)
|
|
123
161
|
return;
|
|
124
162
|
res.locals.jobCallbackSent = true;
|
|
163
|
+
// eslint-disable-next-line no-console
|
|
164
|
+
console.log('[knative-job-fn] Function completed', {
|
|
165
|
+
workerId: ctx.workerId,
|
|
166
|
+
jobId: ctx.jobId,
|
|
167
|
+
databaseId: ctx.databaseId,
|
|
168
|
+
statusCode: res.statusCode
|
|
169
|
+
});
|
|
125
170
|
void sendJobCallback(ctx, 'success');
|
|
126
171
|
});
|
|
127
172
|
}
|
|
@@ -153,6 +198,33 @@ exports.default = {
|
|
|
153
198
|
// eslint-disable-next-line no-console
|
|
154
199
|
console.error('[knative-job-fn] Failed to send error callback', err);
|
|
155
200
|
}
|
|
201
|
+
// Log the full error context for debugging.
|
|
202
|
+
try {
|
|
203
|
+
const headers = getHeaders(req);
|
|
204
|
+
// Some error types (e.g. GraphQL ClientError) expose response info.
|
|
205
|
+
const errorDetails = {
|
|
206
|
+
message: error?.message,
|
|
207
|
+
name: error?.name,
|
|
208
|
+
stack: error?.stack
|
|
209
|
+
};
|
|
210
|
+
if (error?.response) {
|
|
211
|
+
errorDetails.response = {
|
|
212
|
+
status: error.response.status,
|
|
213
|
+
statusText: error.response.statusText,
|
|
214
|
+
errors: error.response.errors,
|
|
215
|
+
data: error.response.data
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
// eslint-disable-next-line no-console
|
|
219
|
+
console.error('[knative-job-fn] Function error', {
|
|
220
|
+
headers,
|
|
221
|
+
path: req.originalUrl || req.url,
|
|
222
|
+
error: errorDetails
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
// never throw from the error logger
|
|
227
|
+
}
|
|
156
228
|
res.status(200).json({ message: error.message });
|
|
157
229
|
});
|
|
158
230
|
app.listen(port, cb);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/knative-job-fn",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "knative job fn",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"homepage": "https://github.com/constructive-io/jobs/tree/master/packages/knative-job-fn#readme",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"body-parser": "1.19.0",
|
|
32
|
-
"express": "
|
|
32
|
+
"express": "5.2.1"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "976cc9e0e09201c7df40518a1797f4178fc21c2c"
|
|
35
35
|
}
|