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

Register Update handler dynamically #500

Merged
merged 6 commits into from
Sep 10, 2024
Merged

Register Update handler dynamically #500

merged 6 commits into from
Sep 10, 2024

Conversation

roxblnfk
Copy link
Collaborator

@roxblnfk roxblnfk commented Sep 9, 2024

What was changed

Added Workflow::registerUpdate($name, $handler, $validator) to register updates dynamically

#[WorkflowMethod]
public function handler()
{
   Workflow::registerUpdate(
      'my-update',
      fn(Task $task) => $this->queue->push($task),
      fn(Task $task) => $this->isValidTask($task) or throw new \InvalidArgumentException('Invalid task'),
   );
}

Checklist

  1. Closes [Feature Request] Dynamic Update handler #497
  2. How was this tested: added autotests
  3. Documentation: PHP SDK: update documentation about updates documentation#3075

Copy link

vercel bot commented Sep 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
php ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 9:58am

src/Workflow.php Outdated
Comment on lines 395 to 397
* public function handler()
* {
* Workflow::registerUpdate(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a little strange for the example to be registering the handler in a function called handler which is also the workflow method. Maybe just call the function exampleWorkflow or something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the function wrapper for all Workflow::register* methods.

@roxblnfk roxblnfk merged commit 17e6150 into master Sep 10, 2024
92 checks passed
@roxblnfk roxblnfk deleted the dynamic-update branch September 10, 2024 16:36
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

Successfully merging this pull request may close these issues.

[Feature Request] Dynamic Update handler
2 participants