-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Workflow Invocation Methods #432
Conversation
Do we have an opportunity here to make invocation of child workflows have the same syntax as invoking workflows from the handler (and transactions and communicators also)? |
This traced back to when we implemented child workflows. I tried to use the same invoke syntax but the issue was recursive return type inference loop. If developers forgot to specify a return type for a workflow, then Typescript compiler will complain "method doesn't exist on the return value of Back then we discussed a solution: we can enforce people to always explicitly specify the return type for a workflow. |
So, if we could avoid this problem cleanly, then that is what we would want? |
Yes, it would be much cleaner! Do you have an idea of how to do it? Harry tried back when we first did |
I would like time to take a shot at it tomorrow. |
invokeWorkflow<T extends object>(object: T, workflowUUID?: string): SyncHandlerWfFuncs<T> { | ||
return this.mainInvoke(object, workflowUUID, false) as unknown as SyncHandlerWfFuncs<T>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh invokeWorkflow
doesn't really convey the synchronous aspect of the call. What about something super explicit like runWorkflowToCompletion
or startWorkflowSync
, invokeWorkflowAndWait
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
People intuitively expect invocation to be synchronous (invoke
itself is synchronous) so calling it invokeWorkflow
is clear, anything more complex may be confusing.
Documentation for dbos-inc/dbos-transact-ts#432
This PR introduces two new methods for invoking workflows from handlers. For workflow bar in class Foo with argument arg:
ctxt.startWorkflow(Foo).bar(arg)
starts the workflow and returns its handle. This is equivalent to the currentctxt.invoke(Foo).bar(arg)
.ctxt.invokeWorkflow(Foo).bar(arg)
executes the workflow and returns its result. This is equivalent to the currentctxt.invoke(foo).bar(arg).then((x)=>x.getResult())
. The latter is very unintuitive and is tripping users up.To avoid confusion, we also deprecate calling
invoke
on workflows--use one of the new methods instead.My hope is that this makes it much clearer to users what is actually happening when a handler invokes a workflow.