Skip to content

Expose Activity and Workflow instance from context#593

Merged
roxblnfk merged 11 commits into
masterfrom
context-instance
May 1, 2025
Merged

Expose Activity and Workflow instance from context#593
roxblnfk merged 11 commits into
masterfrom
context-instance

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Apr 11, 2025

Copy link
Copy Markdown
Collaborator

What was changed

  • Added Activity::getInstance() and Workflow::getInstance()
  • Changed workflow execution flow:
    • First, the Workflow is initialized.
      • It is recommended not to make calls to start Activity, ChildWorkflow, Timer, etc.
      • If the #[WorkflowInit] attribute is present, the arguments are resolved.
    • WorkflowInboundCallInterceptor::execute() is called
      • Arguments from the previous step are used, but they can be overridden.
    • Workflow Handler is called.
  • Now errors from WorkflowInboundCallInterceptor::execute() are recorded in the Workflow history.

Tests:

  • Acceptance Tests: added ability to customize workers per TaskQueue in tests.
  • Added tests for workflow dynamic handlers.

Why?

Checklist

  1. Closes [Feature Request] Access to workflow/activity instance from context #546
  2. How was this tested: added tests
  3. Any docs updates needed?

@vercel

vercel Bot commented Apr 11, 2025

Copy link
Copy Markdown

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 May 1, 2025 0:32am

@roxblnfk
roxblnfk marked this pull request as ready for review April 17, 2025 11:54
@roxblnfk
roxblnfk requested review from Sushisource and wolfy-j April 17, 2025 11:57
Comment on lines +188 to +190
// Initialize workflow instance
//
// Resolve arguments if #[WorkflowInit] is used

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Something we do in the other SDKs is we actually run the init method in a special "readonly" context that will throw errors if the user attempts to issue any commands during init. I dunno if that's something that you can readily enforce, but if possible it's a nice bit of safety.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Now any request from the constructor will throw an exception.
image

Workflow Context will no longer be readonly right after the init stage before the interceptor method WorkflowInboundCallsInterceptor::execute is run.

@roxblnfk
roxblnfk merged commit 4f17d8e into master May 1, 2025
@roxblnfk
roxblnfk deleted the context-instance branch May 1, 2025 13:48
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] Access to workflow/activity instance from context

3 participants