@hatchet-dev/typescript-sdk 1.5.2 → 1.5.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/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/dispatcher/dispatcher.d.ts +5 -0
- package/protoc/dispatcher/dispatcher.js +35 -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 +25 -2
- package/v1/client/worker/context.js +63 -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
|
@@ -158,7 +158,12 @@ export interface AssignedAction {
|
|
|
158
158
|
childWorkflowKey?: string | undefined;
|
|
159
159
|
/** (optional) the parent workflow run id (if this is a child workflow) */
|
|
160
160
|
parentWorkflowRunId?: string | undefined;
|
|
161
|
+
/** (optional) the priority of the run */
|
|
161
162
|
priority: number;
|
|
163
|
+
/** (optional) the workflow id */
|
|
164
|
+
workflowId?: string | undefined;
|
|
165
|
+
/** (optional) the workflow version id */
|
|
166
|
+
workflowVersionId?: string | undefined;
|
|
162
167
|
}
|
|
163
168
|
export interface WorkerListenRequest {
|
|
164
169
|
/** the id of the worker */
|
|
@@ -1094,6 +1094,8 @@ function createBaseAssignedAction() {
|
|
|
1094
1094
|
childWorkflowKey: undefined,
|
|
1095
1095
|
parentWorkflowRunId: undefined,
|
|
1096
1096
|
priority: 0,
|
|
1097
|
+
workflowId: undefined,
|
|
1098
|
+
workflowVersionId: undefined,
|
|
1097
1099
|
};
|
|
1098
1100
|
}
|
|
1099
1101
|
exports.AssignedAction = {
|
|
@@ -1152,6 +1154,12 @@ exports.AssignedAction = {
|
|
|
1152
1154
|
if (message.priority !== 0) {
|
|
1153
1155
|
writer.uint32(144).int32(message.priority);
|
|
1154
1156
|
}
|
|
1157
|
+
if (message.workflowId !== undefined) {
|
|
1158
|
+
writer.uint32(154).string(message.workflowId);
|
|
1159
|
+
}
|
|
1160
|
+
if (message.workflowVersionId !== undefined) {
|
|
1161
|
+
writer.uint32(162).string(message.workflowVersionId);
|
|
1162
|
+
}
|
|
1155
1163
|
return writer;
|
|
1156
1164
|
},
|
|
1157
1165
|
decode(input, length) {
|
|
@@ -1287,6 +1295,20 @@ exports.AssignedAction = {
|
|
|
1287
1295
|
message.priority = reader.int32();
|
|
1288
1296
|
continue;
|
|
1289
1297
|
}
|
|
1298
|
+
case 19: {
|
|
1299
|
+
if (tag !== 154) {
|
|
1300
|
+
break;
|
|
1301
|
+
}
|
|
1302
|
+
message.workflowId = reader.string();
|
|
1303
|
+
continue;
|
|
1304
|
+
}
|
|
1305
|
+
case 20: {
|
|
1306
|
+
if (tag !== 162) {
|
|
1307
|
+
break;
|
|
1308
|
+
}
|
|
1309
|
+
message.workflowVersionId = reader.string();
|
|
1310
|
+
continue;
|
|
1311
|
+
}
|
|
1290
1312
|
}
|
|
1291
1313
|
if ((tag & 7) === 4 || tag === 0) {
|
|
1292
1314
|
break;
|
|
@@ -1325,6 +1347,10 @@ exports.AssignedAction = {
|
|
|
1325
1347
|
? globalThis.String(object.parentWorkflowRunId)
|
|
1326
1348
|
: undefined,
|
|
1327
1349
|
priority: isSet(object.priority) ? globalThis.Number(object.priority) : 0,
|
|
1350
|
+
workflowId: isSet(object.workflowId) ? globalThis.String(object.workflowId) : undefined,
|
|
1351
|
+
workflowVersionId: isSet(object.workflowVersionId)
|
|
1352
|
+
? globalThis.String(object.workflowVersionId)
|
|
1353
|
+
: undefined,
|
|
1328
1354
|
};
|
|
1329
1355
|
},
|
|
1330
1356
|
toJSON(message) {
|
|
@@ -1383,13 +1409,19 @@ exports.AssignedAction = {
|
|
|
1383
1409
|
if (message.priority !== 0) {
|
|
1384
1410
|
obj.priority = Math.round(message.priority);
|
|
1385
1411
|
}
|
|
1412
|
+
if (message.workflowId !== undefined) {
|
|
1413
|
+
obj.workflowId = message.workflowId;
|
|
1414
|
+
}
|
|
1415
|
+
if (message.workflowVersionId !== undefined) {
|
|
1416
|
+
obj.workflowVersionId = message.workflowVersionId;
|
|
1417
|
+
}
|
|
1386
1418
|
return obj;
|
|
1387
1419
|
},
|
|
1388
1420
|
create(base) {
|
|
1389
1421
|
return exports.AssignedAction.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
1390
1422
|
},
|
|
1391
1423
|
fromPartial(object) {
|
|
1392
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
1424
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
1393
1425
|
const message = createBaseAssignedAction();
|
|
1394
1426
|
message.tenantId = (_a = object.tenantId) !== null && _a !== void 0 ? _a : '';
|
|
1395
1427
|
message.workflowRunId = (_b = object.workflowRunId) !== null && _b !== void 0 ? _b : '';
|
|
@@ -1409,6 +1441,8 @@ exports.AssignedAction = {
|
|
|
1409
1441
|
message.childWorkflowKey = (_r = object.childWorkflowKey) !== null && _r !== void 0 ? _r : undefined;
|
|
1410
1442
|
message.parentWorkflowRunId = (_s = object.parentWorkflowRunId) !== null && _s !== void 0 ? _s : undefined;
|
|
1411
1443
|
message.priority = (_t = object.priority) !== null && _t !== void 0 ? _t : 0;
|
|
1444
|
+
message.workflowId = (_u = object.workflowId) !== null && _u !== void 0 ? _u : undefined;
|
|
1445
|
+
message.workflowVersionId = (_v = object.workflowVersionId) !== null && _v !== void 0 ? _v : undefined;
|
|
1412
1446
|
return message;
|
|
1413
1447
|
},
|
|
1414
1448
|
};
|
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,11 +36,12 @@ 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;
|
|
39
43
|
get cancelled(): boolean;
|
|
44
|
+
cancel(): Promise<void>;
|
|
40
45
|
/**
|
|
41
46
|
* Retrieves the output of a parent task.
|
|
42
47
|
* @param parentTask - The a CreateTaskOpts or string of the parent task name.
|
|
@@ -87,6 +92,16 @@ export declare class Context<T, K = {}> {
|
|
|
87
92
|
* @returns The workflow run ID.
|
|
88
93
|
*/
|
|
89
94
|
workflowRunId(): string;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the workflow ID of the currently running workflow.
|
|
97
|
+
* @returns The workflow id.
|
|
98
|
+
*/
|
|
99
|
+
workflowId(): string | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Gets the workflow version ID of the currently running workflow.
|
|
102
|
+
* @returns The workflow version ID.
|
|
103
|
+
*/
|
|
104
|
+
workflowVersionId(): string | undefined;
|
|
90
105
|
/**
|
|
91
106
|
* Gets the ID of the current task run.
|
|
92
107
|
* @returns The task run ID.
|
|
@@ -101,8 +116,16 @@ export declare class Context<T, K = {}> {
|
|
|
101
116
|
* Logs a message from the current task.
|
|
102
117
|
* @param message - The message to log.
|
|
103
118
|
* @param level - The log level (optional).
|
|
119
|
+
* @deprecated use ctx.logger.infoger.info, ctx.logger.infoger.debug, ctx.logger.infoger.warn, ctx.logger.infoger.error, ctx.logger.infoger.trace instead
|
|
104
120
|
*/
|
|
105
|
-
log(message: string, level?: LogLevel): void
|
|
121
|
+
log(message: string, level?: LogLevel, extra?: LogExtra): Promise<void> | Promise<void[]>;
|
|
122
|
+
get logger(): {
|
|
123
|
+
info: (message: string, extra?: any) => Promise<void> | Promise<void[]>;
|
|
124
|
+
debug: (message: string, extra?: any) => Promise<void> | Promise<void[]>;
|
|
125
|
+
warn: (message: string, extra?: LogExtra) => Promise<void> | Promise<void[]>;
|
|
126
|
+
error: (message: string, extra?: LogExtra) => Promise<void> | Promise<void[]>;
|
|
127
|
+
util: (key: string, message: string, extra?: LogExtra) => void | Promise<void>;
|
|
128
|
+
};
|
|
106
129
|
/**
|
|
107
130
|
* Refreshes the timeout for the current task.
|
|
108
131
|
* @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;
|
|
@@ -54,6 +54,15 @@ class Context {
|
|
|
54
54
|
get cancelled() {
|
|
55
55
|
return this.controller.signal.aborted;
|
|
56
56
|
}
|
|
57
|
+
cancel() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
yield this.v1.runs.cancel({
|
|
60
|
+
ids: [this.action.stepRunId],
|
|
61
|
+
});
|
|
62
|
+
// optimistically abort the run
|
|
63
|
+
this.controller.abort();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
57
66
|
/**
|
|
58
67
|
* Retrieves the output of a parent task.
|
|
59
68
|
* @param parentTask - The a CreateTaskOpts or string of the parent task name.
|
|
@@ -92,7 +101,7 @@ class Context {
|
|
|
92
101
|
errors() {
|
|
93
102
|
const errors = this.data.step_run_errors || {};
|
|
94
103
|
if (Object.keys(errors).length === 0) {
|
|
95
|
-
this.
|
|
104
|
+
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
105
|
}
|
|
97
106
|
return errors;
|
|
98
107
|
}
|
|
@@ -140,6 +149,20 @@ class Context {
|
|
|
140
149
|
workflowRunId() {
|
|
141
150
|
return this.action.workflowRunId;
|
|
142
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Gets the workflow ID of the currently running workflow.
|
|
154
|
+
* @returns The workflow id.
|
|
155
|
+
*/
|
|
156
|
+
workflowId() {
|
|
157
|
+
return this.action.workflowId;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Gets the workflow version ID of the currently running workflow.
|
|
161
|
+
* @returns The workflow version ID.
|
|
162
|
+
*/
|
|
163
|
+
workflowVersionId() {
|
|
164
|
+
return this.action.workflowVersionId;
|
|
165
|
+
}
|
|
143
166
|
/**
|
|
144
167
|
* Gets the ID of the current task run.
|
|
145
168
|
* @returns The task run ID.
|
|
@@ -158,29 +181,56 @@ class Context {
|
|
|
158
181
|
* Logs a message from the current task.
|
|
159
182
|
* @param message - The message to log.
|
|
160
183
|
* @param level - The log level (optional).
|
|
184
|
+
* @deprecated use ctx.logger.infoger.info, ctx.logger.infoger.debug, ctx.logger.infoger.warn, ctx.logger.infoger.error, ctx.logger.infoger.trace instead
|
|
161
185
|
*/
|
|
162
|
-
log(message, level) {
|
|
186
|
+
log(message, level, extra) {
|
|
163
187
|
const { stepRunId } = this.action;
|
|
164
188
|
if (!stepRunId) {
|
|
165
189
|
// log a warning
|
|
166
|
-
this.
|
|
167
|
-
return;
|
|
190
|
+
this._logger.warn('cannot log from context without stepRunId');
|
|
191
|
+
return Promise.resolve();
|
|
168
192
|
}
|
|
169
193
|
const logger = this.v1.config.logger('ctx', this.v1.config.log_level);
|
|
194
|
+
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);
|
|
195
|
+
const promises = [];
|
|
170
196
|
if (!level || level === 'INFO') {
|
|
171
|
-
logger.info(message);
|
|
197
|
+
promises.push(logger.info(message, contextExtra));
|
|
172
198
|
}
|
|
173
199
|
else if (level === 'DEBUG') {
|
|
174
|
-
logger.debug(message);
|
|
200
|
+
promises.push(logger.debug(message, contextExtra));
|
|
175
201
|
}
|
|
176
202
|
else if (level === 'WARN') {
|
|
177
|
-
logger.warn(message);
|
|
203
|
+
promises.push(logger.warn(message, extra === null || extra === void 0 ? void 0 : extra.error, contextExtra));
|
|
178
204
|
}
|
|
179
205
|
else if (level === 'ERROR') {
|
|
180
|
-
logger.error(message);
|
|
206
|
+
promises.push(logger.error(message, extra === null || extra === void 0 ? void 0 : extra.error, contextExtra));
|
|
181
207
|
}
|
|
182
208
|
// 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);
|
|
209
|
+
promises.push(this.v1.event.putLog(stepRunId, message, level, this.retryCount(), extra === null || extra === void 0 ? void 0 : extra.extra));
|
|
210
|
+
return Promise.all(promises);
|
|
211
|
+
}
|
|
212
|
+
get logger() {
|
|
213
|
+
return {
|
|
214
|
+
info: (message, extra) => {
|
|
215
|
+
return this.log(message, 'INFO', { extra });
|
|
216
|
+
},
|
|
217
|
+
debug: (message, extra) => {
|
|
218
|
+
return this.log(message, 'DEBUG', { extra });
|
|
219
|
+
},
|
|
220
|
+
warn: (message, extra) => {
|
|
221
|
+
return this.log(message, 'WARN', extra);
|
|
222
|
+
},
|
|
223
|
+
error: (message, extra) => {
|
|
224
|
+
return this.log(message, 'ERROR', extra);
|
|
225
|
+
},
|
|
226
|
+
util: (key, message, extra) => {
|
|
227
|
+
const logger = this.v1.config.logger('ctx', this.v1.config.log_level);
|
|
228
|
+
if (!logger.util) {
|
|
229
|
+
return Promise.resolve();
|
|
230
|
+
}
|
|
231
|
+
return logger.util(key, message, extra === null || extra === void 0 ? void 0 : extra.extra);
|
|
232
|
+
},
|
|
233
|
+
};
|
|
184
234
|
}
|
|
185
235
|
/**
|
|
186
236
|
* Refreshes the timeout for the current task.
|
|
@@ -192,7 +242,7 @@ class Context {
|
|
|
192
242
|
const { stepRunId } = this.action;
|
|
193
243
|
if (!stepRunId) {
|
|
194
244
|
// log a warning
|
|
195
|
-
this.
|
|
245
|
+
this._logger.warn('cannot refresh timeout from context without stepRunId');
|
|
196
246
|
return;
|
|
197
247
|
}
|
|
198
248
|
yield this.v1._v0.dispatcher.refreshTimeout(incrementBy, stepRunId);
|
|
@@ -220,7 +270,7 @@ class Context {
|
|
|
220
270
|
const { stepRunId } = this.action;
|
|
221
271
|
if (!stepRunId) {
|
|
222
272
|
// log a warning
|
|
223
|
-
this.
|
|
273
|
+
this._logger.warn('cannot log from context without stepRunId');
|
|
224
274
|
return;
|
|
225
275
|
}
|
|
226
276
|
yield this.v1._v0.event.putStream(stepRunId, data);
|
|
@@ -240,7 +290,7 @@ class Context {
|
|
|
240
290
|
throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${workflowName} is not registered on the worker`);
|
|
241
291
|
}
|
|
242
292
|
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 });
|
|
293
|
+
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
294
|
this.spawnIndex += 1;
|
|
245
295
|
return { workflowName, opts: finalOpts };
|
|
246
296
|
}
|
|
@@ -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.4";
|
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;
|