@hatchet-dev/typescript-sdk 1.5.2 → 1.5.3
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/clients/event/event-client.d.ts +2 -2
- package/clients/event/event-client.js +42 -36
- package/clients/hatchet-client/hatchet-logger.d.ts +9 -6
- package/clients/hatchet-client/hatchet-logger.js +29 -5
- package/examples/bulk-fanout-worker.js +1 -1
- package/examples/byo-logger.js +29 -34
- package/examples/fanout-worker.js +1 -1
- package/examples/logger.js +1 -1
- package/package.json +1 -1
- package/protoc/events/events.d.ts +2 -0
- package/protoc/events/events.js +26 -2
- package/step.js +1 -1
- package/util/logger/logger.d.ts +8 -5
- package/v1/client/worker/context.d.ts +14 -2
- package/v1/client/worker/context.js +40 -13
- package/v1/examples/simple/workflow-with-child.d.ts +3 -0
- package/v1/examples/simple/workflow-with-child.js +13 -3
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/workflow.d.ts +2 -2
|
@@ -24,6 +24,6 @@ export declare class EventClient {
|
|
|
24
24
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
25
25
|
push<T>(type: string, input: T, options?: PushEventOptions): Promise<import("../../protoc/events/events").Event>;
|
|
26
26
|
bulkPush<T>(type: string, inputs: EventWithMetadata<T>[], options?: PushEventOptions): Promise<import("../../protoc/events/events").Events>;
|
|
27
|
-
putLog(stepRunId: string, log: string, level?: LogLevel): void
|
|
28
|
-
putStream(stepRunId: string, data: string | Uint8Array): void
|
|
27
|
+
putLog(stepRunId: string, log: string, level?: LogLevel, taskRetryCount?: number, metadata?: Record<string, any>): Promise<void>;
|
|
28
|
+
putStream(stepRunId: string, data: string | Uint8Array): Promise<void>;
|
|
29
29
|
}
|
|
@@ -82,46 +82,52 @@ class EventClient {
|
|
|
82
82
|
throw new hatchet_error_1.default(e.message);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
putLog(stepRunId, log, level) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
putLog(stepRunId, log, level, taskRetryCount, metadata) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const createdAt = new Date();
|
|
88
|
+
if (log.length > 1000) {
|
|
89
|
+
this.logger.warn(`log is too long, skipping: ${log.length} characters`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// fire and forget the log
|
|
93
|
+
yield this.client
|
|
94
|
+
.putLog({
|
|
95
|
+
stepRunId,
|
|
96
|
+
createdAt,
|
|
97
|
+
message: log,
|
|
98
|
+
level: level || LogLevel.INFO,
|
|
99
|
+
taskRetryCount,
|
|
100
|
+
metadata: metadata ? JSON.stringify(metadata) : undefined,
|
|
101
|
+
})
|
|
102
|
+
.catch((e) => {
|
|
103
|
+
// log a warning, but this is not a fatal error
|
|
104
|
+
this.logger.warn(`Could not put log: ${e.message}`);
|
|
105
|
+
});
|
|
102
106
|
});
|
|
103
107
|
}
|
|
104
108
|
putStream(stepRunId, data) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const createdAt = new Date();
|
|
111
|
+
let dataBytes;
|
|
112
|
+
if (typeof data === 'string') {
|
|
113
|
+
dataBytes = new TextEncoder().encode(data);
|
|
114
|
+
}
|
|
115
|
+
else if (data instanceof Uint8Array) {
|
|
116
|
+
dataBytes = data;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw new Error('Invalid data type. Expected string or Uint8Array.');
|
|
120
|
+
}
|
|
121
|
+
(0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
return this.client.putStreamEvent({
|
|
123
|
+
stepRunId,
|
|
124
|
+
createdAt,
|
|
125
|
+
message: dataBytes,
|
|
126
|
+
});
|
|
127
|
+
}), this.logger).catch((e) => {
|
|
128
|
+
// log a warning, but this is not a fatal error
|
|
129
|
+
this.logger.warn(`Could not put log: ${e.message}`);
|
|
121
130
|
});
|
|
122
|
-
}), this.logger).catch((e) => {
|
|
123
|
-
// log a warning, but this is not a fatal error
|
|
124
|
-
this.logger.warn(`Could not put log: ${e.message}`);
|
|
125
131
|
});
|
|
126
132
|
}
|
|
127
133
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { Logger, LogLevel } from '../../util/logger';
|
|
1
|
+
import { LogExtra, Logger, LogLevel } from '../../util/logger';
|
|
2
2
|
export declare const DEFAULT_LOGGER: (context: string, logLevel?: LogLevel) => HatchetLogger;
|
|
3
|
+
type UtilKeys = 'trace';
|
|
3
4
|
export declare class HatchetLogger implements Logger {
|
|
4
5
|
private logLevel;
|
|
5
6
|
private context;
|
|
6
7
|
constructor(context: string, logLevel?: LogLevel);
|
|
7
8
|
private log;
|
|
8
|
-
debug(message: string): void
|
|
9
|
-
info(message: string): void
|
|
10
|
-
green(message: string): void
|
|
11
|
-
warn(message: string, error?: Error): void
|
|
12
|
-
error(message: string, error?: Error): void
|
|
9
|
+
debug(message: string): Promise<void>;
|
|
10
|
+
info(message: string): Promise<void>;
|
|
11
|
+
green(message: string): Promise<void>;
|
|
12
|
+
warn(message: string, error?: Error): Promise<void>;
|
|
13
|
+
error(message: string, error?: Error): Promise<void>;
|
|
14
|
+
util(key: UtilKeys, message: string, extra?: LogExtra): void | Promise<void>;
|
|
13
15
|
}
|
|
16
|
+
export {};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.HatchetLogger = exports.DEFAULT_LOGGER = void 0;
|
|
4
13
|
/* eslint-disable no-console */
|
|
@@ -39,19 +48,34 @@ class HatchetLogger {
|
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
50
|
debug(message) {
|
|
42
|
-
this
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
yield this.log('DEBUG', message, '35');
|
|
53
|
+
});
|
|
43
54
|
}
|
|
44
55
|
info(message) {
|
|
45
|
-
this
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
yield this.log('INFO', message);
|
|
58
|
+
});
|
|
46
59
|
}
|
|
47
60
|
green(message) {
|
|
48
|
-
this
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
yield this.log('INFO', message, '32');
|
|
63
|
+
});
|
|
49
64
|
}
|
|
50
65
|
warn(message, error) {
|
|
51
|
-
this
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
yield this.log('WARN', `${message} ${error}`, '93');
|
|
68
|
+
});
|
|
52
69
|
}
|
|
53
70
|
error(message, error) {
|
|
54
|
-
this
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
yield this.log('ERROR', `${message} ${error}`, '91');
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
util(key, message, extra) {
|
|
76
|
+
if (key === 'trace') {
|
|
77
|
+
this.log('INFO', `trace: ${message}`, '35');
|
|
78
|
+
}
|
|
55
79
|
}
|
|
56
80
|
}
|
|
57
81
|
exports.HatchetLogger = HatchetLogger;
|
|
@@ -33,7 +33,7 @@ const parentWorkflow = {
|
|
|
33
33
|
}));
|
|
34
34
|
const spawnedWorkflows = yield ctx.spawnWorkflows(workflowRequests);
|
|
35
35
|
const results = yield Promise.all(spawnedWorkflows.map((workflowRef) => workflowRef.output.then((result) => {
|
|
36
|
-
ctx.
|
|
36
|
+
ctx.logger.info('spawned workflow result:');
|
|
37
37
|
return result;
|
|
38
38
|
})));
|
|
39
39
|
console.log('spawned workflow results:', results);
|
package/examples/byo-logger.js
CHANGED
|
@@ -22,20 +22,27 @@ class PinoLogger {
|
|
|
22
22
|
this.logLevel = logLevel;
|
|
23
23
|
this.context = context;
|
|
24
24
|
}
|
|
25
|
-
debug(message) {
|
|
26
|
-
logger.debug(message);
|
|
25
|
+
debug(message, extra) {
|
|
26
|
+
logger.debug(message, extra);
|
|
27
27
|
}
|
|
28
|
-
info(message) {
|
|
29
|
-
logger.info(message);
|
|
28
|
+
info(message, extra) {
|
|
29
|
+
logger.info(message, extra);
|
|
30
30
|
}
|
|
31
|
-
green(message) {
|
|
32
|
-
logger.info(`%c${message}
|
|
31
|
+
green(message, extra) {
|
|
32
|
+
logger.info(`%c${message}`, extra);
|
|
33
33
|
}
|
|
34
|
-
warn(message, error) {
|
|
35
|
-
logger.warn(`${message} ${error}
|
|
34
|
+
warn(message, error, extra) {
|
|
35
|
+
logger.warn(`${message} ${error}`, extra);
|
|
36
36
|
}
|
|
37
|
-
error(message, error) {
|
|
38
|
-
logger.error(`${message} ${error}
|
|
37
|
+
error(message, error, extra) {
|
|
38
|
+
logger.error(`${message} ${error}`, extra);
|
|
39
|
+
}
|
|
40
|
+
// optional util method
|
|
41
|
+
util(key, message, extra) {
|
|
42
|
+
// for example you may want to expose a trace method
|
|
43
|
+
if (key === 'trace') {
|
|
44
|
+
logger.info('trace', extra);
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
48
|
const hatchet = sdk_1.default.init({
|
|
@@ -44,34 +51,22 @@ const hatchet = sdk_1.default.init({
|
|
|
44
51
|
});
|
|
45
52
|
// !!
|
|
46
53
|
// > Use the logger
|
|
47
|
-
const
|
|
48
|
-
|
|
54
|
+
const workflow = hatchet.task({
|
|
55
|
+
name: 'byo-logger-example',
|
|
56
|
+
fn: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
// eslint-disable-next-line no-plusplus
|
|
58
|
+
for (let i = 0; i < 5; i++) {
|
|
59
|
+
logger.info(`log message ${i}`);
|
|
60
|
+
}
|
|
61
|
+
return { step1: 'completed step run' };
|
|
62
|
+
}),
|
|
49
63
|
});
|
|
50
|
-
const workflow = {
|
|
51
|
-
id: 'byo-logger-example',
|
|
52
|
-
description: 'An example showing how to pass a custom logger to Hatchet',
|
|
53
|
-
on: {
|
|
54
|
-
event: 'byo-logger:spawn',
|
|
55
|
-
},
|
|
56
|
-
steps: [
|
|
57
|
-
{
|
|
58
|
-
name: 'logger-step1',
|
|
59
|
-
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
-
// eslint-disable-next-line no-plusplus
|
|
61
|
-
for (let i = 0; i < 5; i++) {
|
|
62
|
-
logger.info(`log message ${i}`);
|
|
63
|
-
yield sleep(500);
|
|
64
|
-
}
|
|
65
|
-
return { step1: 'completed step run' };
|
|
66
|
-
}),
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
};
|
|
70
64
|
// !!
|
|
71
65
|
function main() {
|
|
72
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const worker = yield hatchet.worker('byo-logger-worker',
|
|
74
|
-
|
|
67
|
+
const worker = yield hatchet.worker('byo-logger-worker', {
|
|
68
|
+
workflows: [workflow],
|
|
69
|
+
});
|
|
75
70
|
worker.start();
|
|
76
71
|
});
|
|
77
72
|
}
|
|
@@ -28,7 +28,7 @@ const parentWorkflow = {
|
|
|
28
28
|
const promises = Array.from({ length: 3 }, (_, i) => ctx
|
|
29
29
|
.spawnWorkflow('child-workflow', { input: `child-input-${i}` }, { additionalMetadata: { childKey: 'childValue' } })
|
|
30
30
|
.then((result) => {
|
|
31
|
-
ctx.
|
|
31
|
+
ctx.logger.info('spawned workflow result:');
|
|
32
32
|
return result.output;
|
|
33
33
|
}));
|
|
34
34
|
const results = yield Promise.all(promises);
|
package/examples/logger.js
CHANGED
|
@@ -33,7 +33,7 @@ const workflow = {
|
|
|
33
33
|
// log in a for loop
|
|
34
34
|
// eslint-disable-next-line no-plusplus
|
|
35
35
|
for (let i = 0; i < 10; i++) {
|
|
36
|
-
ctx.
|
|
36
|
+
ctx.logger.info(`log message ${i}`);
|
|
37
37
|
yield sleep(200);
|
|
38
38
|
}
|
|
39
39
|
return { step1: 'completed step run' };
|
package/package.json
CHANGED
package/protoc/events/events.js
CHANGED
|
@@ -208,7 +208,14 @@ exports.Events = {
|
|
|
208
208
|
},
|
|
209
209
|
};
|
|
210
210
|
function createBasePutLogRequest() {
|
|
211
|
-
return {
|
|
211
|
+
return {
|
|
212
|
+
stepRunId: '',
|
|
213
|
+
createdAt: undefined,
|
|
214
|
+
message: '',
|
|
215
|
+
level: undefined,
|
|
216
|
+
metadata: '',
|
|
217
|
+
taskRetryCount: undefined,
|
|
218
|
+
};
|
|
212
219
|
}
|
|
213
220
|
exports.PutLogRequest = {
|
|
214
221
|
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
@@ -227,6 +234,9 @@ exports.PutLogRequest = {
|
|
|
227
234
|
if (message.metadata !== '') {
|
|
228
235
|
writer.uint32(42).string(message.metadata);
|
|
229
236
|
}
|
|
237
|
+
if (message.taskRetryCount !== undefined) {
|
|
238
|
+
writer.uint32(48).int32(message.taskRetryCount);
|
|
239
|
+
}
|
|
230
240
|
return writer;
|
|
231
241
|
},
|
|
232
242
|
decode(input, length) {
|
|
@@ -271,6 +281,13 @@ exports.PutLogRequest = {
|
|
|
271
281
|
message.metadata = reader.string();
|
|
272
282
|
continue;
|
|
273
283
|
}
|
|
284
|
+
case 6: {
|
|
285
|
+
if (tag !== 48) {
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
message.taskRetryCount = reader.int32();
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
274
291
|
}
|
|
275
292
|
if ((tag & 7) === 4 || tag === 0) {
|
|
276
293
|
break;
|
|
@@ -286,6 +303,9 @@ exports.PutLogRequest = {
|
|
|
286
303
|
message: isSet(object.message) ? globalThis.String(object.message) : '',
|
|
287
304
|
level: isSet(object.level) ? globalThis.String(object.level) : undefined,
|
|
288
305
|
metadata: isSet(object.metadata) ? globalThis.String(object.metadata) : '',
|
|
306
|
+
taskRetryCount: isSet(object.taskRetryCount)
|
|
307
|
+
? globalThis.Number(object.taskRetryCount)
|
|
308
|
+
: undefined,
|
|
289
309
|
};
|
|
290
310
|
},
|
|
291
311
|
toJSON(message) {
|
|
@@ -305,19 +325,23 @@ exports.PutLogRequest = {
|
|
|
305
325
|
if (message.metadata !== '') {
|
|
306
326
|
obj.metadata = message.metadata;
|
|
307
327
|
}
|
|
328
|
+
if (message.taskRetryCount !== undefined) {
|
|
329
|
+
obj.taskRetryCount = Math.round(message.taskRetryCount);
|
|
330
|
+
}
|
|
308
331
|
return obj;
|
|
309
332
|
},
|
|
310
333
|
create(base) {
|
|
311
334
|
return exports.PutLogRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
312
335
|
},
|
|
313
336
|
fromPartial(object) {
|
|
314
|
-
var _a, _b, _c, _d, _e;
|
|
337
|
+
var _a, _b, _c, _d, _e, _f;
|
|
315
338
|
const message = createBasePutLogRequest();
|
|
316
339
|
message.stepRunId = (_a = object.stepRunId) !== null && _a !== void 0 ? _a : '';
|
|
317
340
|
message.createdAt = (_b = object.createdAt) !== null && _b !== void 0 ? _b : undefined;
|
|
318
341
|
message.message = (_c = object.message) !== null && _c !== void 0 ? _c : '';
|
|
319
342
|
message.level = (_d = object.level) !== null && _d !== void 0 ? _d : undefined;
|
|
320
343
|
message.metadata = (_e = object.metadata) !== null && _e !== void 0 ? _e : '';
|
|
344
|
+
message.taskRetryCount = (_f = object.taskRetryCount) !== null && _f !== void 0 ? _f : undefined;
|
|
321
345
|
return message;
|
|
322
346
|
},
|
|
323
347
|
};
|
package/step.js
CHANGED
|
@@ -301,7 +301,7 @@ class V0Context {
|
|
|
301
301
|
this.logger.warn('cannot log from context without stepRunId');
|
|
302
302
|
return;
|
|
303
303
|
}
|
|
304
|
-
this.v0.event.putLog(stepRunId, message, level);
|
|
304
|
+
this.v0.event.putLog(stepRunId, message, level, this.retryCount());
|
|
305
305
|
}
|
|
306
306
|
/**
|
|
307
307
|
* Refreshes the timeout for the current task.
|
package/util/logger/logger.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { JsonObject } from '../../v1';
|
|
2
|
+
export type LogExtra = JsonObject;
|
|
1
3
|
export declare abstract class Logger {
|
|
2
|
-
abstract debug(message: string): void
|
|
3
|
-
abstract info(message: string): void
|
|
4
|
-
abstract green(message: string): void
|
|
5
|
-
abstract warn(message: string, error?: Error): void
|
|
6
|
-
abstract error(message: string, error?: Error): void
|
|
4
|
+
abstract debug(message: string, extra?: LogExtra): void | Promise<void>;
|
|
5
|
+
abstract info(message: string, extra?: LogExtra): void | Promise<void>;
|
|
6
|
+
abstract green(message: string, extra?: LogExtra): void | Promise<void>;
|
|
7
|
+
abstract warn(message: string, error?: Error, extra?: LogExtra): void | Promise<void>;
|
|
8
|
+
abstract error(message: string, error?: Error, extra?: LogExtra): void | Promise<void>;
|
|
9
|
+
abstract util?(key: string, message: string, extra?: LogExtra): void | Promise<void>;
|
|
7
10
|
}
|
|
8
11
|
export type LogLevel = 'OFF' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
9
12
|
export declare enum LogLevelEnum {
|
|
@@ -16,6 +16,10 @@ type ChildRunOpts = RunOpts & {
|
|
|
16
16
|
key?: string;
|
|
17
17
|
sticky?: boolean;
|
|
18
18
|
};
|
|
19
|
+
type LogExtra = {
|
|
20
|
+
extra?: any;
|
|
21
|
+
error?: Error;
|
|
22
|
+
};
|
|
19
23
|
interface ContextData<T, K> {
|
|
20
24
|
input: T;
|
|
21
25
|
triggers: TriggerData;
|
|
@@ -32,7 +36,7 @@ export declare class Context<T, K = {}> {
|
|
|
32
36
|
v1: HatchetClient;
|
|
33
37
|
worker: ContextWorker;
|
|
34
38
|
overridesData: Record<string, any>;
|
|
35
|
-
|
|
39
|
+
_logger: Logger;
|
|
36
40
|
spawnIndex: number;
|
|
37
41
|
constructor(action: Action, v1: HatchetClient, worker: V1Worker);
|
|
38
42
|
get abortController(): AbortController;
|
|
@@ -101,8 +105,16 @@ export declare class Context<T, K = {}> {
|
|
|
101
105
|
* Logs a message from the current task.
|
|
102
106
|
* @param message - The message to log.
|
|
103
107
|
* @param level - The log level (optional).
|
|
108
|
+
* @deprecated use ctx.logger.infoger.info, ctx.logger.infoger.debug, ctx.logger.infoger.warn, ctx.logger.infoger.error, ctx.logger.infoger.trace instead
|
|
104
109
|
*/
|
|
105
|
-
log(message: string, level?: LogLevel): void
|
|
110
|
+
log(message: string, level?: LogLevel, extra?: LogExtra): Promise<void> | Promise<void[]>;
|
|
111
|
+
get logger(): {
|
|
112
|
+
info: (message: string, extra?: any) => Promise<void> | Promise<void[]>;
|
|
113
|
+
debug: (message: string, extra?: any) => Promise<void> | Promise<void[]>;
|
|
114
|
+
warn: (message: string, extra?: LogExtra) => Promise<void> | Promise<void[]>;
|
|
115
|
+
error: (message: string, extra?: LogExtra) => Promise<void> | Promise<void[]>;
|
|
116
|
+
util: (key: string, message: string, extra?: LogExtra) => void | Promise<void>;
|
|
117
|
+
};
|
|
106
118
|
/**
|
|
107
119
|
* Refreshes the timeout for the current task.
|
|
108
120
|
* @param incrementBy - The interval by which to increment the timeout.
|
|
@@ -34,7 +34,7 @@ class Context {
|
|
|
34
34
|
this.action = action;
|
|
35
35
|
this.v1 = v1;
|
|
36
36
|
this.worker = new step_1.ContextWorker(worker);
|
|
37
|
-
this.
|
|
37
|
+
this._logger = v1.config.logger(`Context Logger`, v1.config.log_level);
|
|
38
38
|
// if this is a getGroupKeyRunId, the data is the workflow input
|
|
39
39
|
if (action.getGroupKeyRunId !== '') {
|
|
40
40
|
this.input = data;
|
|
@@ -92,7 +92,7 @@ class Context {
|
|
|
92
92
|
errors() {
|
|
93
93
|
const errors = this.data.step_run_errors || {};
|
|
94
94
|
if (Object.keys(errors).length === 0) {
|
|
95
|
-
this.
|
|
95
|
+
this._logger.error('No run errors found. `ctx.errors` is intended to be run in an on-failure task, and will only work on engine versions more recent than v0.53.10');
|
|
96
96
|
}
|
|
97
97
|
return errors;
|
|
98
98
|
}
|
|
@@ -158,29 +158,56 @@ class Context {
|
|
|
158
158
|
* Logs a message from the current task.
|
|
159
159
|
* @param message - The message to log.
|
|
160
160
|
* @param level - The log level (optional).
|
|
161
|
+
* @deprecated use ctx.logger.infoger.info, ctx.logger.infoger.debug, ctx.logger.infoger.warn, ctx.logger.infoger.error, ctx.logger.infoger.trace instead
|
|
161
162
|
*/
|
|
162
|
-
log(message, level) {
|
|
163
|
+
log(message, level, extra) {
|
|
163
164
|
const { stepRunId } = this.action;
|
|
164
165
|
if (!stepRunId) {
|
|
165
166
|
// log a warning
|
|
166
|
-
this.
|
|
167
|
-
return;
|
|
167
|
+
this._logger.warn('cannot log from context without stepRunId');
|
|
168
|
+
return Promise.resolve();
|
|
168
169
|
}
|
|
169
170
|
const logger = this.v1.config.logger('ctx', this.v1.config.log_level);
|
|
171
|
+
const contextExtra = Object.assign({ workflowRunId: this.action.workflowRunId, taskRunId: this.action.stepRunId, retryCount: this.action.retryCount, workflowName: this.action.jobName }, extra === null || extra === void 0 ? void 0 : extra.extra);
|
|
172
|
+
const promises = [];
|
|
170
173
|
if (!level || level === 'INFO') {
|
|
171
|
-
logger.info(message);
|
|
174
|
+
promises.push(logger.info(message, contextExtra));
|
|
172
175
|
}
|
|
173
176
|
else if (level === 'DEBUG') {
|
|
174
|
-
logger.debug(message);
|
|
177
|
+
promises.push(logger.debug(message, contextExtra));
|
|
175
178
|
}
|
|
176
179
|
else if (level === 'WARN') {
|
|
177
|
-
logger.warn(message);
|
|
180
|
+
promises.push(logger.warn(message, extra === null || extra === void 0 ? void 0 : extra.error, contextExtra));
|
|
178
181
|
}
|
|
179
182
|
else if (level === 'ERROR') {
|
|
180
|
-
logger.error(message);
|
|
183
|
+
promises.push(logger.error(message, extra === null || extra === void 0 ? void 0 : extra.error, contextExtra));
|
|
181
184
|
}
|
|
182
185
|
// FIXME: this is a hack to get around the fact that the log level is not typed
|
|
183
|
-
this.v1.event.putLog(stepRunId, message, level);
|
|
186
|
+
promises.push(this.v1.event.putLog(stepRunId, message, level, this.retryCount(), extra === null || extra === void 0 ? void 0 : extra.extra));
|
|
187
|
+
return Promise.all(promises);
|
|
188
|
+
}
|
|
189
|
+
get logger() {
|
|
190
|
+
return {
|
|
191
|
+
info: (message, extra) => {
|
|
192
|
+
return this.log(message, 'INFO', { extra });
|
|
193
|
+
},
|
|
194
|
+
debug: (message, extra) => {
|
|
195
|
+
return this.log(message, 'DEBUG', { extra });
|
|
196
|
+
},
|
|
197
|
+
warn: (message, extra) => {
|
|
198
|
+
return this.log(message, 'WARN', extra);
|
|
199
|
+
},
|
|
200
|
+
error: (message, extra) => {
|
|
201
|
+
return this.log(message, 'ERROR', extra);
|
|
202
|
+
},
|
|
203
|
+
util: (key, message, extra) => {
|
|
204
|
+
const logger = this.v1.config.logger('ctx', this.v1.config.log_level);
|
|
205
|
+
if (!logger.util) {
|
|
206
|
+
return Promise.resolve();
|
|
207
|
+
}
|
|
208
|
+
return logger.util(key, message, extra === null || extra === void 0 ? void 0 : extra.extra);
|
|
209
|
+
},
|
|
210
|
+
};
|
|
184
211
|
}
|
|
185
212
|
/**
|
|
186
213
|
* Refreshes the timeout for the current task.
|
|
@@ -192,7 +219,7 @@ class Context {
|
|
|
192
219
|
const { stepRunId } = this.action;
|
|
193
220
|
if (!stepRunId) {
|
|
194
221
|
// log a warning
|
|
195
|
-
this.
|
|
222
|
+
this._logger.warn('cannot refresh timeout from context without stepRunId');
|
|
196
223
|
return;
|
|
197
224
|
}
|
|
198
225
|
yield this.v1._v0.dispatcher.refreshTimeout(incrementBy, stepRunId);
|
|
@@ -220,7 +247,7 @@ class Context {
|
|
|
220
247
|
const { stepRunId } = this.action;
|
|
221
248
|
if (!stepRunId) {
|
|
222
249
|
// log a warning
|
|
223
|
-
this.
|
|
250
|
+
this._logger.warn('cannot log from context without stepRunId');
|
|
224
251
|
return;
|
|
225
252
|
}
|
|
226
253
|
yield this.v1._v0.event.putStream(stepRunId, data);
|
|
@@ -240,7 +267,7 @@ class Context {
|
|
|
240
267
|
throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${workflowName} is not registered on the worker`);
|
|
241
268
|
}
|
|
242
269
|
const { workflowRunId, stepRunId } = this.action;
|
|
243
|
-
const finalOpts = Object.assign(Object.assign({}, options), { parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined, _standaloneTaskName: workflow instanceof declaration_1.TaskWorkflowDeclaration ? workflow._standalone_task_name : undefined });
|
|
270
|
+
const finalOpts = Object.assign(Object.assign({}, options), { parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, childKey: options === null || options === void 0 ? void 0 : options.key, desiredWorkerId: sticky ? this.worker.id() : undefined, _standaloneTaskName: workflow instanceof declaration_1.TaskWorkflowDeclaration ? workflow._standalone_task_name : undefined });
|
|
244
271
|
this.spawnIndex += 1;
|
|
245
272
|
return { workflowName, opts: finalOpts };
|
|
246
273
|
}
|
|
@@ -11,6 +11,9 @@ export declare const child1: import("../..").CreateWorkflowTaskOpts<ChildInput,
|
|
|
11
11
|
export declare const child2: import("../..").CreateWorkflowTaskOpts<ChildInput, {
|
|
12
12
|
TransformedMessage: string;
|
|
13
13
|
}>;
|
|
14
|
+
export declare const child3: import("../..").CreateWorkflowTaskOpts<ChildInput, {
|
|
15
|
+
TransformedMessage: string;
|
|
16
|
+
}>;
|
|
14
17
|
export declare const parent: import("../..").TaskWorkflowDeclaration<ParentInput, {
|
|
15
18
|
TransformedMessage: string;
|
|
16
19
|
}>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.parent = exports.child2 = exports.child1 = exports.child = void 0;
|
|
12
|
+
exports.parent = exports.child3 = exports.child2 = exports.child1 = exports.child = void 0;
|
|
13
13
|
// > Declaring a Task
|
|
14
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
15
|
exports.child = hatchet_client_1.hatchet.workflow({
|
|
@@ -18,7 +18,7 @@ exports.child = hatchet_client_1.hatchet.workflow({
|
|
|
18
18
|
exports.child1 = exports.child.task({
|
|
19
19
|
name: 'child1',
|
|
20
20
|
fn: (input, ctx) => {
|
|
21
|
-
ctx.
|
|
21
|
+
ctx.logger.info('hello from the child1', { hello: 'moon' });
|
|
22
22
|
return {
|
|
23
23
|
TransformedMessage: input.Message.toLowerCase(),
|
|
24
24
|
};
|
|
@@ -27,7 +27,17 @@ exports.child1 = exports.child.task({
|
|
|
27
27
|
exports.child2 = exports.child.task({
|
|
28
28
|
name: 'child2',
|
|
29
29
|
fn: (input, ctx) => {
|
|
30
|
-
ctx.
|
|
30
|
+
ctx.logger.info('hello from the child2');
|
|
31
|
+
return {
|
|
32
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
exports.child3 = exports.child.task({
|
|
37
|
+
name: 'child3',
|
|
38
|
+
parents: [exports.child1, exports.child2],
|
|
39
|
+
fn: (input, ctx) => {
|
|
40
|
+
ctx.logger.info('hello from the child3');
|
|
31
41
|
return {
|
|
32
42
|
TransformedMessage: input.Message.toLowerCase(),
|
|
33
43
|
};
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.5.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.5.3";
|
package/version.js
CHANGED
package/workflow.d.ts
CHANGED
|
@@ -387,10 +387,10 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
387
387
|
event: string;
|
|
388
388
|
cron?: undefined;
|
|
389
389
|
} | undefined;
|
|
390
|
+
timeout?: string | undefined;
|
|
390
391
|
version?: string | undefined;
|
|
391
392
|
scheduleTimeout?: string | undefined;
|
|
392
393
|
sticky?: PbStickyStrategy | undefined;
|
|
393
|
-
timeout?: string | undefined;
|
|
394
394
|
onFailure?: {
|
|
395
395
|
name: string;
|
|
396
396
|
timeout?: string | undefined;
|
|
@@ -449,10 +449,10 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
449
449
|
event: string;
|
|
450
450
|
cron?: undefined;
|
|
451
451
|
} | undefined;
|
|
452
|
+
timeout?: string | undefined;
|
|
452
453
|
version?: string | undefined;
|
|
453
454
|
scheduleTimeout?: string | undefined;
|
|
454
455
|
sticky?: PbStickyStrategy | undefined;
|
|
455
|
-
timeout?: string | undefined;
|
|
456
456
|
onFailure?: {
|
|
457
457
|
name: string;
|
|
458
458
|
timeout?: string | undefined;
|