Skip to content

Commit 2bddfb6

Browse files
authored
fix: standalone task key (#1664)
* fix: standalone task key * 1.5.1
1 parent 52a7ae7 commit 2bddfb6

File tree

6 files changed

+39
-20
lines changed

6 files changed

+39
-20
lines changed

sdks/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hatchet-dev/typescript-sdk",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "Background task orchestration & visibility for developers",
55
"types": "dist/index.d.ts",
66
"files": [

sdks/typescript/src/step.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ export class V0Context<T, K = {}> {
472472
const wf = workflows[index].workflow;
473473
if (wf instanceof TaskWorkflowDeclaration) {
474474
// eslint-disable-next-line no-param-reassign
475-
ref._standalone_task_name = wf._standalone_task_name;
475+
ref._standaloneTaskName = wf._standalone_task_name;
476476
}
477477
res.push(ref);
478478
});
@@ -563,7 +563,7 @@ export class V0Context<T, K = {}> {
563563
this.spawnIndex += 1;
564564

565565
if (workflow instanceof TaskWorkflowDeclaration) {
566-
resp._standalone_task_name = workflow._standalone_task_name;
566+
resp._standaloneTaskName = workflow._standalone_task_name;
567567
}
568568

569569
return resp;

sdks/typescript/src/util/workflow-run-ref.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class WorkflowRunRef<T> {
5252
parentWorkflowRunId?: string;
5353
private client: RunListenerClient;
5454
private runs: RunsClient | undefined;
55-
_standalone_task_name?: string;
55+
_standaloneTaskName?: string;
5656

5757
constructor(
5858
workflowRunId:
@@ -63,12 +63,14 @@ export default class WorkflowRunRef<T> {
6363
}>,
6464
client: RunListenerClient,
6565
runsClient?: RunsClient,
66-
parentWorkflowRunId?: string
66+
parentWorkflowRunId?: string,
67+
standaloneTaskName?: string
6768
) {
6869
this.workflowRunId = workflowRunId;
6970
this.parentWorkflowRunId = parentWorkflowRunId;
7071
this.client = client;
7172
this.runs = runsClient;
73+
this._standaloneTaskName = standaloneTaskName;
7274
}
7375

7476
// TODO docstrings
@@ -86,9 +88,7 @@ export default class WorkflowRunRef<T> {
8688
return this.client.stream(workflowRunId);
8789
}
8890

89-
// TODO not sure if i want this to be a get since it might be blocking for a long time..
90-
get output() {
91-
// TODO output for single task workflows
91+
get output(): Promise<T> {
9292
return this.result();
9393
}
9494

@@ -137,12 +137,12 @@ export default class WorkflowRunRef<T> {
137137
}
138138
});
139139

140-
if (!this._standalone_task_name) {
140+
if (!this._standaloneTaskName) {
141141
resolve(outputs as T);
142142
return;
143143
}
144144

145-
resolve(outputs[this._standalone_task_name] as T);
145+
resolve(outputs[this._standaloneTaskName] as T);
146146
return;
147147
}
148148

@@ -154,12 +154,12 @@ export default class WorkflowRunRef<T> {
154154
{} as T
155155
);
156156

157-
if (!this._standalone_task_name) {
157+
if (!this._standaloneTaskName) {
158158
resolve(result);
159159
return;
160160
}
161161

162-
resolve((result as any)[this._standalone_task_name] as T);
162+
resolve((result as any)[this._standaloneTaskName] as T);
163163
return;
164164
}
165165
}

sdks/typescript/src/v1/client/admin.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class AdminClient {
6262
additionalMetadata?: Record<string, string> | undefined;
6363
desiredWorkerId?: string | undefined;
6464
priority?: Priority;
65+
_standaloneTaskName?: string | undefined;
6566
}
6667
) {
6768
let computedName = workflowName;
@@ -85,7 +86,14 @@ export class AdminClient {
8586

8687
const id = resp.workflowRunId;
8788

88-
const ref = new WorkflowRunRef<P>(id, this.listenerClient, this.runs, options?.parentId);
89+
const ref = new WorkflowRunRef<P>(
90+
id,
91+
this.listenerClient,
92+
this.runs,
93+
options?.parentId,
94+
// eslint-disable-next-line no-underscore-dangle
95+
options?._standaloneTaskName
96+
);
8997
await ref.getWorkflowRunId();
9098
return ref;
9199
} catch (e: any) {
@@ -111,6 +119,7 @@ export class AdminClient {
111119
additionalMetadata?: Record<string, string> | undefined;
112120
desiredWorkerId?: string | undefined;
113121
priority?: Priority;
122+
_standaloneTaskName?: string | undefined;
114123
};
115124
}>,
116125
batchSize: number = 500
@@ -159,7 +168,14 @@ export class AdminClient {
159168
const batchResults = bulkTriggerWorkflowResponse.workflowRunIds.map((resp, index) => {
160169
const originalIndex = originalIndices[index];
161170
const { options } = workflowRuns[originalIndex];
162-
return new WorkflowRunRef<P>(resp, this.listenerClient, this.runs, options?.parentId);
171+
return new WorkflowRunRef<P>(
172+
resp,
173+
this.listenerClient,
174+
this.runs,
175+
options?.parentId,
176+
// eslint-disable-next-line no-underscore-dangle
177+
options?._standaloneTaskName
178+
);
163179
});
164180

165181
results.push(...batchResults);

sdks/typescript/src/v1/client/worker/context.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ export class Context<T, K = {}> {
297297
parentStepRunId: stepRunId,
298298
childIndex: this.spawnIndex,
299299
desiredWorkerId: sticky ? this.worker.id() : undefined,
300+
_standaloneTaskName:
301+
workflow instanceof TaskWorkflowDeclaration ? workflow._standalone_task_name : undefined,
300302
};
301303

302304
this.spawnIndex += 1;
@@ -391,7 +393,8 @@ export class Context<T, K = {}> {
391393
input: Q,
392394
options?: ChildRunOpts
393395
): Promise<WorkflowRunRef<P>> {
394-
return this.spawn(workflow, input, options);
396+
const ref = await this.spawn(workflow, input, options);
397+
return ref;
395398
}
396399

397400
/**
@@ -547,7 +550,7 @@ export class Context<T, K = {}> {
547550
const wf = workflows[index].workflow;
548551
if (wf instanceof TaskWorkflowDeclaration) {
549552
// eslint-disable-next-line no-param-reassign
550-
ref._standalone_task_name = wf._standalone_task_name;
553+
ref._standaloneTaskName = wf._standalone_task_name;
551554
}
552555
res.push(ref);
553556
});
@@ -605,7 +608,7 @@ export class Context<T, K = {}> {
605608
this.spawnIndex += 1;
606609

607610
if (workflow instanceof TaskWorkflowDeclaration) {
608-
resp._standalone_task_name = workflow._standalone_task_name;
611+
resp._standaloneTaskName = workflow._standalone_task_name;
609612
}
610613

611614
return resp;

sdks/typescript/src/v1/declaration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class BaseWorkflowDeclaration<
274274
const res = await this.client.admin.runWorkflow<I, O>(this.name, input, options);
275275

276276
if (_standaloneTaskName) {
277-
res._standalone_task_name = _standaloneTaskName;
277+
res._standaloneTaskName = _standaloneTaskName;
278278
}
279279

280280
return res;
@@ -339,7 +339,7 @@ export class BaseWorkflowDeclaration<
339339
const wf = input[index].workflow;
340340
if (wf instanceof TaskWorkflowDeclaration) {
341341
// eslint-disable-next-line no-param-reassign
342-
ref._standalone_task_name = wf._standalone_task_name;
342+
ref._standaloneTaskName = wf._standalone_task_name;
343343
}
344344
res.push(ref.result());
345345
});
@@ -349,7 +349,7 @@ export class BaseWorkflowDeclaration<
349349
const res = await this.client.admin.runWorkflow<I, O>(this.definition.name, input, options);
350350

351351
if (_standaloneTaskName) {
352-
res._standalone_task_name = _standaloneTaskName;
352+
res._standaloneTaskName = _standaloneTaskName;
353353
}
354354

355355
return res.result() as Promise<O>;

0 commit comments

Comments
 (0)