-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set LastHeartbeatDetails on activity failure (#2354)
- Loading branch information
1 parent
ff333ca
commit 9a8894a
Showing
12 changed files
with
160 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ral-sdk/src/main/java/io/temporal/internal/activity/InternalActivityExecutionContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.internal.activity; | ||
|
||
import io.temporal.activity.ActivityExecutionContext; | ||
|
||
/** | ||
* Internal context object passed to an Activity implementation, providing more internal details | ||
* than the user facing {@link ActivityExecutionContext}. | ||
*/ | ||
public interface InternalActivityExecutionContext extends ActivityExecutionContext { | ||
/** Get the latest value of {@link ActivityExecutionContext#heartbeat(Object)}. */ | ||
Object getLastHeartbeatValue(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
temporal-sdk/src/test/java/io/temporal/activity/ActivityHeartbeatSentOnFailureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.activity; | ||
|
||
import io.temporal.testing.internal.SDKTestOptions; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.Workflow; | ||
import io.temporal.workflow.shared.TestActivities; | ||
import io.temporal.workflow.shared.TestWorkflows; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class ActivityHeartbeatSentOnFailureTest { | ||
|
||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestWorkflowImpl.class) | ||
.setActivityImplementations(new HeartBeatingActivityImpl()) | ||
.build(); | ||
|
||
/** Tests that the last Activity#heartbeat value is sent if the activity fails. */ | ||
@Test | ||
public void activityHeartbeatSentOnFailure() { | ||
TestWorkflows.NoArgsWorkflow workflow = | ||
testWorkflowRule.newWorkflowStub(TestWorkflows.NoArgsWorkflow.class); | ||
workflow.execute(); | ||
} | ||
|
||
public static class TestWorkflowImpl implements TestWorkflows.NoArgsWorkflow { | ||
|
||
private final TestActivities.NoArgsActivity activities = | ||
Workflow.newActivityStub( | ||
TestActivities.NoArgsActivity.class, | ||
SDKTestOptions.newActivityOptions20sScheduleToClose()); | ||
|
||
@Override | ||
public void execute() { | ||
activities.execute(); | ||
} | ||
} | ||
|
||
public static class HeartBeatingActivityImpl implements TestActivities.NoArgsActivity { | ||
@Override | ||
public void execute() { | ||
// If the heartbeat details are "3", then we know that the last heartbeat was sent. | ||
if (Activity.getExecutionContext().getHeartbeatDetails(String.class).orElse("").equals("3")) { | ||
return; | ||
} | ||
// Send 3 heartbeats and then fail, expecting the last heartbeat to be sent | ||
// even though the activity fails and the last two attempts would normally be throttled. | ||
Activity.getExecutionContext().heartbeat("1"); | ||
Activity.getExecutionContext().heartbeat("2"); | ||
Activity.getExecutionContext().heartbeat("3"); | ||
throw new RuntimeException("simulated failure"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters