Skip to content

Conversation

@tsurdilo
Copy link
Contributor

autoheartbeat sample ..support cancelation

Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
@tsurdilo tsurdilo requested review from a team and antmendoza as code owners June 20, 2025 04:43
Copy link
Member

@antmendoza antmendoza left a comment

Choose a reason for hiding this comment

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

thanks @tsurdilo, disregard my previous comment (deleted). I got confused with the other PR that uses the same branch name

}
}
}
return super.execute(input);
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 the activity function is executed twice when there is a heartbeat, here and in line 74 of this same file

return super.execute(input);
}

public interface AutoHeartbeaterCancellationCallback {
Copy link
Member

Choose a reason for hiding this comment

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

this is not used, I believe it can be deleted

@tsurdilo
Copy link
Contributor Author

thanks for review @antmendoza . will update over weekend

Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
@tsurdilo
Copy link
Contributor Author

applied updates

@@ -0,0 +1,16 @@
# Auto-heartbeating sample for activities that define HeartbeatTimeout
Copy link
Contributor

Choose a reason for hiding this comment

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

This sample should be linked from the top level readmen

if (activityHeartbeatTimeout != null
&& activityHeartbeatTimeout.getSeconds() > 0
&& !Boolean.parseBoolean(System.getProperty("sample.disableAutoHeartbeat"))) {
System.out.println(
Copy link
Contributor

Choose a reason for hiding this comment

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

should be a logger no?

Copy link
Contributor

Choose a reason for hiding this comment

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

That applies to pretty much all logging in this sample

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Quinn-With-Two-Ns system outs are either in activity or activity interceptor. if you want we can add activity logger

Copy link
Contributor

Choose a reason for hiding this comment

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

They should still use an sl4j logger

}

@Override
public void cancelActivity() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why cancel through a signal and not just use normal workflow cancellation/.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah will add a "run" for workflow cancelation too. forgot i think

@antmendoza
Copy link
Member

@tsurdilo we tested this and I think the activity continues running after the cancellation request is received and the heartbeat stops. I am not sure if there is a way to stop it, @Quinn-With-Two-Ns might have some input
cc @dan8f

@Quinn-With-Two-Ns
Copy link
Contributor

@antmendoza The users activity code has to choose to stop, you would need to add a mechanism for the auto heartbeat to "signal" the activity to stop and the activity has to respond to that. This is why we don't really recommend auto heartbeating, it isn's some magic solution, users code still needs to handle cancellation.

Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
@tsurdilo
Copy link
Contributor Author

tsurdilo commented Jul 1, 2025

added a "warning" message in sample readme to make sure users are aware of the pitfalls of autoheartbeating approach

Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
@tsurdilo tsurdilo merged commit 902591b into main Jul 1, 2025
10 checks passed
@tsurdilo tsurdilo deleted the autoheartbeat branch July 1, 2025 20:14
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.

4 participants