Skip to content
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

Create type safe way to pass workflow arguments to ScheduleWorkflow #1

Open
bergundy opened this issue Jan 4, 2022 · 5 comments
Open

Comments

@bergundy
Copy link

bergundy commented Jan 4, 2022

Current example in README is both type unsafe and doesn't work because functions are not JSON serializable, this helper addresses the issue and adds type-safety:

Schedule.args = <W extends Workflow>(
  workflow: W | string, opts: ScheduleWorkflowOptions<W>
): [string, ScheduleWorkflowOptions<W>] {
    return [typeof workflow === 'string' ? workflow : workflow.name, args];
}

client.execute(Schedule, { args: Schedule.args(myWorkflow3, { args: [1, 2] }) })

Also this type uses the child workflow options which aren't the same as the client's workflow options, you might want to fix that while you're at it https://github.com/sw-yx/temporal-time-utils/blob/d2f6d7aebcc6c537c518e49abadd1245ce4b126d/packages/temporal-time-utils/ScheduleWorkflow.ts#L30

@swyxio
Copy link
Collaborator

swyxio commented Jan 5, 2022

it works because i just grab the name of the function if given a function 🤷‍♂️ but appreciate the other points... will get to it eventually

@swyxio
Copy link
Collaborator

swyxio commented Jan 5, 2022

Also this type uses the child workflow options which aren't the same as the client's workflow options

regarding this - i actually think this is correct, because these types are meant for the child workflow, NOT the top/parent/scheduler workflow

@bergundy
Copy link
Author

bergundy commented Jan 5, 2022

it works because i just grab the name of the function if given a function 🤷‍♂️ but appreciate the other points... will get to it eventually

I don't think it should work because you need to serialize the function into a payload which isn't possible

@bergundy
Copy link
Author

bergundy commented Jan 5, 2022

Also this type uses the child workflow options which aren't the same as the client's workflow options

You're correct, I forgot that the workflow is always executed as a child

@swyxio
Copy link
Collaborator

swyxio commented Jan 5, 2022

I don't think it should work because you need to serialize the function into a payload which isn't possible

ok ok i understand you now. good point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants