fix: standalone task key (#1664)

* fix: standalone task key

* 1.5.1
This commit is contained in:
Gabe Ruttner
2025-05-02 10:49:48 -07:00
committed by GitHub
parent 52a7ae78a4
commit 2bddfb6e26
6 changed files with 39 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@hatchet-dev/typescript-sdk",
"version": "1.5.0",
"version": "1.5.1",
"description": "Background task orchestration & visibility for developers",
"types": "dist/index.d.ts",
"files": [

View File

@@ -472,7 +472,7 @@ export class V0Context<T, K = {}> {
const wf = workflows[index].workflow;
if (wf instanceof TaskWorkflowDeclaration) {
// eslint-disable-next-line no-param-reassign
ref._standalone_task_name = wf._standalone_task_name;
ref._standaloneTaskName = wf._standalone_task_name;
}
res.push(ref);
});
@@ -563,7 +563,7 @@ export class V0Context<T, K = {}> {
this.spawnIndex += 1;
if (workflow instanceof TaskWorkflowDeclaration) {
resp._standalone_task_name = workflow._standalone_task_name;
resp._standaloneTaskName = workflow._standalone_task_name;
}
return resp;

View File

@@ -52,7 +52,7 @@ export default class WorkflowRunRef<T> {
parentWorkflowRunId?: string;
private client: RunListenerClient;
private runs: RunsClient | undefined;
_standalone_task_name?: string;
_standaloneTaskName?: string;
constructor(
workflowRunId:
@@ -63,12 +63,14 @@ export default class WorkflowRunRef<T> {
}>,
client: RunListenerClient,
runsClient?: RunsClient,
parentWorkflowRunId?: string
parentWorkflowRunId?: string,
standaloneTaskName?: string
) {
this.workflowRunId = workflowRunId;
this.parentWorkflowRunId = parentWorkflowRunId;
this.client = client;
this.runs = runsClient;
this._standaloneTaskName = standaloneTaskName;
}
// TODO docstrings
@@ -86,9 +88,7 @@ export default class WorkflowRunRef<T> {
return this.client.stream(workflowRunId);
}
// TODO not sure if i want this to be a get since it might be blocking for a long time..
get output() {
// TODO output for single task workflows
get output(): Promise<T> {
return this.result();
}
@@ -137,12 +137,12 @@ export default class WorkflowRunRef<T> {
}
});
if (!this._standalone_task_name) {
if (!this._standaloneTaskName) {
resolve(outputs as T);
return;
}
resolve(outputs[this._standalone_task_name] as T);
resolve(outputs[this._standaloneTaskName] as T);
return;
}
@@ -154,12 +154,12 @@ export default class WorkflowRunRef<T> {
{} as T
);
if (!this._standalone_task_name) {
if (!this._standaloneTaskName) {
resolve(result);
return;
}
resolve((result as any)[this._standalone_task_name] as T);
resolve((result as any)[this._standaloneTaskName] as T);
return;
}
}

View File

@@ -62,6 +62,7 @@ export class AdminClient {
additionalMetadata?: Record<string, string> | undefined;
desiredWorkerId?: string | undefined;
priority?: Priority;
_standaloneTaskName?: string | undefined;
}
) {
let computedName = workflowName;
@@ -85,7 +86,14 @@ export class AdminClient {
const id = resp.workflowRunId;
const ref = new WorkflowRunRef<P>(id, this.listenerClient, this.runs, options?.parentId);
const ref = new WorkflowRunRef<P>(
id,
this.listenerClient,
this.runs,
options?.parentId,
// eslint-disable-next-line no-underscore-dangle
options?._standaloneTaskName
);
await ref.getWorkflowRunId();
return ref;
} catch (e: any) {
@@ -111,6 +119,7 @@ export class AdminClient {
additionalMetadata?: Record<string, string> | undefined;
desiredWorkerId?: string | undefined;
priority?: Priority;
_standaloneTaskName?: string | undefined;
};
}>,
batchSize: number = 500
@@ -159,7 +168,14 @@ export class AdminClient {
const batchResults = bulkTriggerWorkflowResponse.workflowRunIds.map((resp, index) => {
const originalIndex = originalIndices[index];
const { options } = workflowRuns[originalIndex];
return new WorkflowRunRef<P>(resp, this.listenerClient, this.runs, options?.parentId);
return new WorkflowRunRef<P>(
resp,
this.listenerClient,
this.runs,
options?.parentId,
// eslint-disable-next-line no-underscore-dangle
options?._standaloneTaskName
);
});
results.push(...batchResults);

View File

@@ -297,6 +297,8 @@ export class Context<T, K = {}> {
parentStepRunId: stepRunId,
childIndex: this.spawnIndex,
desiredWorkerId: sticky ? this.worker.id() : undefined,
_standaloneTaskName:
workflow instanceof TaskWorkflowDeclaration ? workflow._standalone_task_name : undefined,
};
this.spawnIndex += 1;
@@ -391,7 +393,8 @@ export class Context<T, K = {}> {
input: Q,
options?: ChildRunOpts
): Promise<WorkflowRunRef<P>> {
return this.spawn(workflow, input, options);
const ref = await this.spawn(workflow, input, options);
return ref;
}
/**
@@ -547,7 +550,7 @@ export class Context<T, K = {}> {
const wf = workflows[index].workflow;
if (wf instanceof TaskWorkflowDeclaration) {
// eslint-disable-next-line no-param-reassign
ref._standalone_task_name = wf._standalone_task_name;
ref._standaloneTaskName = wf._standalone_task_name;
}
res.push(ref);
});
@@ -605,7 +608,7 @@ export class Context<T, K = {}> {
this.spawnIndex += 1;
if (workflow instanceof TaskWorkflowDeclaration) {
resp._standalone_task_name = workflow._standalone_task_name;
resp._standaloneTaskName = workflow._standalone_task_name;
}
return resp;

View File

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