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

Add workflow init support #2222

Merged
merged 6 commits into from
Sep 17, 2024

Conversation

Quinn-With-Two-Ns
Copy link
Contributor

Add workflow init support to allow users to run code before signal/update handlers:

  • If the workflow implementation defines a no-arg constructor that is used to maintain backwards compatibility
  • SDK checks if the workflow implementation defines a constructor annotated with @WorkflowInit
  • SDK validates at registration time the constructor meets all requirments.
  • If a constructor is annotated with @WorkflowInit we treat exceptions thrown by as if they are thrown from the main workflow method

closes #865

for (Constructor<?> ctor : clazz.getDeclaredConstructors()) {
WorkflowInit wfInit = ctor.getAnnotation(WorkflowInit.class);
if (wfInit == null) {
if (ctor.getParameterCount() == 0) {
Copy link
Member

@cretz cretz Sep 16, 2024

Choose a reason for hiding this comment

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

Suggested change
if (ctor.getParameterCount() == 0) {
if (ctor.getParameterCount() == 0 && Modifier.isPublic(ctor.getModifiers())) {

Small thing, but I figure we want to ensure default constructor is public (I assume this isn't backwards incompatible as it would have broken before) and ignore non-public constructors

@Quinn-With-Two-Ns Quinn-With-Two-Ns merged commit 21d15ae into temporalio:master Sep 17, 2024
8 checks passed
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.

Add init method to workflow
2 participants