@goatlab/tasks-adapter-hatchet 0.2.3 → 0.3.0
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.
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ShouldQueue, TaskConnector, TaskStatus } from '@goatlab/tasks-core';
|
|
2
2
|
import { Hatchet } from '@hatchet-dev/typescript-sdk';
|
|
3
3
|
export declare class HatchetConnector implements TaskConnector<object> {
|
|
4
|
-
private token;
|
|
5
|
-
private hostAndPort;
|
|
6
|
-
private apiUrl;
|
|
7
|
-
private logLevel;
|
|
8
|
-
private tenantId;
|
|
4
|
+
private readonly token;
|
|
5
|
+
private readonly hostAndPort;
|
|
6
|
+
private readonly apiUrl;
|
|
7
|
+
private readonly logLevel;
|
|
8
|
+
private readonly tenantId;
|
|
9
9
|
constructor({ token, hostAndPort, apiUrl, logLevel, tenantId }: {
|
|
10
10
|
token: string;
|
|
11
11
|
hostAndPort?: string;
|
package/dist/HatchetConnector.js
CHANGED
|
@@ -4,6 +4,11 @@ exports.HatchetConnector = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const js_utils_1 = require("@goatlab/js-utils");
|
|
6
6
|
const typescript_sdk_1 = require("@hatchet-dev/typescript-sdk");
|
|
7
|
+
// Default configuration constants
|
|
8
|
+
const DEFAULT_HOST_PORT = 'localhost:7077';
|
|
9
|
+
const DEFAULT_API_URL = 'http://localhost:8888';
|
|
10
|
+
const DEFAULT_LOG_LEVEL = 'INFO';
|
|
11
|
+
const DEFAULT_TENANT_ID = '707d0855-80ab-4e1f-a156-f1c4546cbf52';
|
|
7
12
|
class HatchetConnector {
|
|
8
13
|
token;
|
|
9
14
|
hostAndPort;
|
|
@@ -12,19 +17,19 @@ class HatchetConnector {
|
|
|
12
17
|
tenantId;
|
|
13
18
|
constructor({ token, hostAndPort, apiUrl, logLevel, tenantId }) {
|
|
14
19
|
this.token = token || '';
|
|
15
|
-
this.hostAndPort = hostAndPort ||
|
|
16
|
-
this.apiUrl = apiUrl ||
|
|
17
|
-
this.logLevel = logLevel ||
|
|
20
|
+
this.hostAndPort = hostAndPort || DEFAULT_HOST_PORT;
|
|
21
|
+
this.apiUrl = apiUrl || DEFAULT_API_URL;
|
|
22
|
+
this.logLevel = logLevel || DEFAULT_LOG_LEVEL;
|
|
18
23
|
this.tenantId = tenantId || '';
|
|
19
24
|
}
|
|
20
25
|
getHatchetClient() {
|
|
21
26
|
const hatchet = typescript_sdk_1.Hatchet.init({
|
|
22
27
|
token: this.token,
|
|
23
|
-
host_port: this.hostAndPort
|
|
24
|
-
api_url: this.apiUrl
|
|
25
|
-
log_level: this.logLevel
|
|
28
|
+
host_port: this.hostAndPort,
|
|
29
|
+
api_url: this.apiUrl,
|
|
30
|
+
log_level: this.logLevel,
|
|
26
31
|
// This is the default tenantId for local development
|
|
27
|
-
tenant_id: this.tenantId ||
|
|
32
|
+
tenant_id: this.tenantId || DEFAULT_TENANT_ID,
|
|
28
33
|
namespace: '',
|
|
29
34
|
tls_config: {
|
|
30
35
|
tls_strategy: 'none'
|
|
@@ -40,11 +45,13 @@ class HatchetConnector {
|
|
|
40
45
|
});
|
|
41
46
|
}
|
|
42
47
|
async startWorker({ workerName, tasks, slots = 100 }) {
|
|
48
|
+
// Pre-map workflows to avoid repeated processing
|
|
49
|
+
const workflows = tasks.map(task => this.getHatchetTask(task));
|
|
43
50
|
const worker = await this.getHatchetClient().worker(`${workerName}-${js_utils_1.Ids.nanoId(5)}`, {
|
|
44
51
|
// 👀 Declare the workflows that the worker can execute
|
|
45
|
-
workflows
|
|
52
|
+
workflows,
|
|
46
53
|
// 👀 Declare the number of concurrent task runs the worker can accept
|
|
47
|
-
slots
|
|
54
|
+
slots
|
|
48
55
|
});
|
|
49
56
|
void worker.start();
|
|
50
57
|
// Give the worker some time to start
|
|
@@ -58,13 +65,16 @@ class HatchetConnector {
|
|
|
58
65
|
*/
|
|
59
66
|
async getStatus(id) {
|
|
60
67
|
const { data } = await this.getHatchetClient().api.v1TaskGet(id);
|
|
68
|
+
// Extract values once
|
|
69
|
+
const input = data.input;
|
|
70
|
+
const taskName = data.actionId.split(':')[0] || '';
|
|
61
71
|
return {
|
|
62
72
|
id,
|
|
63
73
|
attempts: data.attempt || 1,
|
|
64
|
-
payload:
|
|
74
|
+
payload: input?.input || {},
|
|
65
75
|
status: data.status,
|
|
66
76
|
created: data.metadata.createdAt,
|
|
67
|
-
name:
|
|
77
|
+
name: taskName,
|
|
68
78
|
nextRun: null,
|
|
69
79
|
nextRunMinutes: null,
|
|
70
80
|
output: data.output
|
|
@@ -86,13 +96,14 @@ class HatchetConnector {
|
|
|
86
96
|
});
|
|
87
97
|
const result = await hatchet.runNoWait(params.taskBody);
|
|
88
98
|
const taskId = await result.runId;
|
|
99
|
+
const now = new Date().toISOString();
|
|
89
100
|
return {
|
|
90
101
|
id: taskId,
|
|
91
102
|
name: result._standaloneTaskName,
|
|
92
103
|
output: '',
|
|
93
104
|
attempts: 0,
|
|
94
105
|
status: 'QUEUED',
|
|
95
|
-
created:
|
|
106
|
+
created: now,
|
|
96
107
|
nextRun: null,
|
|
97
108
|
nextRunMinutes: null
|
|
98
109
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HatchetConnector.js","sourceRoot":"","sources":["../src/HatchetConnector.ts"],"names":[],"mappings":";;;;AAAA,gDAA6C;AAM7C,gEAAqD;AAErD,MAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"HatchetConnector.js","sourceRoot":"","sources":["../src/HatchetConnector.ts"],"names":[],"mappings":";;;;AAAA,gDAA6C;AAM7C,gEAAqD;AAErD,kCAAkC;AAClC,MAAM,iBAAiB,GAAG,gBAAgB,CAAA;AAC1C,MAAM,eAAe,GAAG,uBAAuB,CAAA;AAC/C,MAAM,iBAAiB,GAAG,MAAM,CAAA;AAChC,MAAM,iBAAiB,GAAG,sCAAsC,CAAA;AAEhE,MAAa,gBAAgB;IACV,KAAK,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