mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-02-15 04:39:26 -06:00
@@ -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": [
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user