Skip to content

Commit

Permalink
Add signal/activities and rename interceptor feature (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison authored Oct 24, 2023
1 parent cc11799 commit bad3e30
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 23 deletions.
4 changes: 2 additions & 2 deletions features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import (
update_activities "github.com/temporalio/features/features/update/activities"
update_async_accepted "github.com/temporalio/features/features/update/async_accepted"
update_basic "github.com/temporalio/features/features/update/basic"
update_client_interceptor "github.com/temporalio/features/features/update/client_interceptor"
update_deduplication "github.com/temporalio/features/features/update/deduplication"
update_intercept "github.com/temporalio/features/features/update/intercept"
update_non_durable_reject "github.com/temporalio/features/features/update/non_durable_reject"
update_self "github.com/temporalio/features/features/update/self"
update_task_failure "github.com/temporalio/features/features/update/task_failure"
Expand Down Expand Up @@ -89,7 +89,7 @@ func init() {
update_async_accepted.Feature,
update_basic.Feature,
update_deduplication.Feature,
update_intercept.Feature,
update_client_interceptor.Feature,
update_non_durable_reject.Feature,
update_self.Feature,
update_task_failure.Feature,
Expand Down
8 changes: 8 additions & 0 deletions features/signal/activities/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Run activities from within a Workflow Signal

Workflows can run activities from within a Signal handler.

# Detailed spec

Workflow Signal handlers are like workflow code in that they can invoke and wait on activities.
This test invokes a number of activities within the Signal and blocks on them, returning from the Signal when they have all completed.
38 changes: 38 additions & 0 deletions features/signal/activities/feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Feature } from '@temporalio/harness';
import * as wf from '@temporalio/workflow';
import * as assert from 'assert';

const mySignal = wf.defineSignal<any[]>('mySignal');
const activityCount = 5;
const activityResult = 6;

const activitiesImpl = {
async myActivity(): Promise<number> {
return activityResult;
},
};

const activities = wf.proxyActivities<typeof activitiesImpl>({
startToCloseTimeout: '5s',
});

export const feature = new Feature({
workflow,
activities: activitiesImpl,
checkResult: async (_, handle) => {
await handle.signal(mySignal);
const result = await handle.result();
assert.equal(result, activityResult * activityCount);
},
});

export async function workflow(): Promise<number> {
let total = 0;
wf.setHandler(mySignal, async () => {
const promises = Array.from({ length: activityCount }, activities.myActivity);
const counts = await Promise.all(promises);
total = counts.reduce((a, b) => a + b, 0);
});
await wf.condition(() => total > 0);
return total;
}
9 changes: 3 additions & 6 deletions features/update/activities/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Run activities from within a workflow update

Workflows can run activities from within an update handler
Workflows can run activities from within an update handler.

# Detailed spec

Workflow update handlers are like workflow code in that they can run for
indefinitely long periods but must do so by invoking and waiting on activites.
This test invokes a number of activities within the update and blocks on them,
returning from the update when they have all completed.

Workflow update handlers are like workflow code in that they can invoke and wait on activities.
This test invokes a number of activities within the update and blocks on them, returning from the update when they have all completed.
3 changes: 1 addition & 2 deletions features/update/async_accepted/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Updates can be invoked asynchronously by waiting on the ACCEPTED state.
# Detailed spec

It will be possible to invoke an update and indicate that the calling RPC client
wants the RPC call to block on on completion of the update but rather on the the
wants the RPC call to block not on completion of the update but rather on the the
update passing validation on the workflow - this is called the "Accepted" state.
The update continues to execute to completion despite there being no caller
waiting on its outcome.
Expand All @@ -15,4 +15,3 @@ workflow ID, run ID, and update ID) can create a handle to that update and await
the outcome of the update call. Outcomes returned from these asynchronous
updates are the same as those that would have been returned inline had the
update been invoked synchronously.

8 changes: 8 additions & 0 deletions features/update/client_interceptor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Update Calls Can Be Intercepted

Client Interceptors can intercept and modify update requests

# Detailed spec

A client interceptor can be configured that modifies the arguments sent by a client to an Update handler.
The modification is reflected in the Update response.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package update.intercept;
package update.client_interceptor;

import io.temporal.client.WorkflowClientOptions;
import io.temporal.common.interceptors.WorkflowClientCallsInterceptor;
Expand Down
10 changes: 0 additions & 10 deletions features/update/intercept/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion features/update/task_failure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ the caller side.
The error received by the caller will be through the handle.Get call and will
contain the string contents of the panic/exception message. Panics/Exceptions out of validation
handlers are equivalent to rejections from a durability perspective while panics/exceptions
from the main execution function are the equivalent of panicing/throwing in a workflow task.
from the main execution function are the equivalent of panicking/throwing in a workflow task.
2 changes: 1 addition & 1 deletion harness/java/io/temporal/sdkfeatures/PreparedFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class PreparedFeature {
update.activities.feature.Impl.class,
update.async_accepted.feature.Impl.class,
update.deduplication.feature.Impl.class,
update.intercept.feature.Impl.class,
update.client_interceptor.feature.Impl.class,
update.non_durable_reject.feature.Impl.class,
update.task_failure.feature.Impl.class,
update.worker_restart.feature.Impl.class,
Expand Down

0 comments on commit bad3e30

Please sign in to comment.