Skip to content

Commit 1e85a18

Browse files
committed
call directly better
1 parent 0ae72e2 commit 1e85a18

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/client/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ export class WorkflowManager {
9797
ReturnValue extends ReturnValueForOptionalValidator<ReturnsValidator> = any,
9898
>(
9999
workflow: WorkflowDefinition<ArgsValidator, ReturnsValidator, ReturnValue>,
100-
): RegisteredMutation<"internal", ObjectType<ArgsValidator>, void> {
100+
): RegisteredMutation<
101+
"internal",
102+
{
103+
fn: "You should not call this directly, call workflow.start instead";
104+
args: ObjectType<ArgsValidator>;
105+
},
106+
void
107+
> {
101108
return workflowMutation(
102109
this.component,
103110
workflow,
@@ -116,7 +123,7 @@ export class WorkflowManager {
116123
async start<F extends FunctionReference<"mutation", "internal">>(
117124
ctx: RunMutationCtx,
118125
workflow: F,
119-
args: FunctionArgs<F>,
126+
args: FunctionArgs<F>["args"],
120127
options?: CallbackOptions & {
121128
/**
122129
* By default, during creation the workflow will be initiated immediately.

src/client/workflowMutation.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const workflowArgs = v.union(
3636
args: v.any(),
3737
}),
3838
);
39-
const INVALID_WORKFLOW_MESSAGE = `Invalid arguments for workflow: Did you invoke the workflow with ctx.runMutation() instead of workflow.start()?`;
39+
const INVALID_WORKFLOW_MESSAGE = `Invalid arguments for workflow: Did you invoke the workflow with ctx.runMutation() instead of workflow.start()? Pro tip: to start a workflow directly from the CLI or dashboard, you can use args '{ fn: "path/to/file:workflowName", args: { ...your workflow args } }'`;
4040

4141
// This function is defined in the calling component but then gets passed by
4242
// function handle to the workflow component for execution. This function runs
@@ -46,7 +46,14 @@ export function workflowMutation<ArgsValidator extends PropertyValidators>(
4646
component: WorkflowComponent,
4747
registered: WorkflowDefinition<ArgsValidator>,
4848
defaultWorkpoolOptions?: WorkpoolOptions,
49-
): RegisteredMutation<"internal", ObjectType<ArgsValidator>, void> {
49+
): RegisteredMutation<
50+
"internal",
51+
{
52+
fn: "You should not call this directly, call workflow.start instead";
53+
args: ObjectType<ArgsValidator>;
54+
},
55+
void
56+
> {
5057
const workpoolOptions = {
5158
...defaultWorkpoolOptions,
5259
...registered.workpoolOptions,
@@ -58,13 +65,13 @@ export function workflowMutation<ArgsValidator extends PropertyValidators>(
5865
}
5966
if ("fn" in args) {
6067
const fn = makeFunctionReference(args.fn);
61-
await ctx.runMutation(component.workflow.create, {
68+
const workflowId = await ctx.runMutation(component.workflow.create, {
6269
workflowName: safeFunctionName(fn),
6370
workflowHandle: await createFunctionHandle(fn),
6471
workflowArgs: args.args,
6572
maxParallelism: workpoolOptions.maxParallelism,
6673
});
67-
return;
74+
return workflowId;
6875
}
6976
const { workflowId, generationNumber } = args;
7077
const { workflow, logLevel, journalEntries, ok } = await ctx.runQuery(

0 commit comments

Comments
 (0)