From 82c38dd954378483c8a7cc49862d524b8abda32e Mon Sep 17 00:00:00 2001 From: Spencer Judge Date: Thu, 22 Feb 2024 15:31:01 -0800 Subject: [PATCH] Also test sched2close timeout & add .net --- .../basic_no_workflow_timeout/feature.cs | 54 +++++++++++++++++++ .../basic_no_workflow_timeout/feature.go | 10 +++- .../basic_no_workflow_timeout/feature.java | 8 ++- .../basic_no_workflow_timeout/feature.py | 4 ++ .../basic_no_workflow_timeout/feature.ts | 4 ++ 5 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 features/activity/basic_no_workflow_timeout/feature.cs diff --git a/features/activity/basic_no_workflow_timeout/feature.cs b/features/activity/basic_no_workflow_timeout/feature.cs new file mode 100644 index 00000000..f029c8ff --- /dev/null +++ b/features/activity/basic_no_workflow_timeout/feature.cs @@ -0,0 +1,54 @@ +namespace activity.basic_no_workflow_timeout; + +using Temporalio.Activities; +using Temporalio.Client; +using Temporalio.Exceptions; +using Temporalio.Features.Harness; +using Temporalio.Worker; +using Temporalio.Workflows; + +class Feature : IFeature +{ + public void ConfigureWorker(Runner runner, TemporalWorkerOptions options) => + options.AddWorkflow().AddAllActivities(new MyActivities(runner.Client)); + + [Workflow] + class MyWorkflow + { + private string? activityResult; + + [WorkflowRun] + public async Task RunAsync() + { + await Workflow.ExecuteActivityAsync( + (MyActivities act) => act.Echo(), + new() + { + ScheduleToCloseTimeout = TimeSpan.FromMinutes(1) + }); + + await Workflow.ExecuteActivityAsync( + (MyActivities act) => act.Echo(), + new() + { + StartToCloseTimeout = TimeSpan.FromMinutes(1) + }); + } + + [WorkflowSignal] + public async Task SetActivityResultAsync(string res) => activityResult = res; + } + + class MyActivities + { + private readonly ITemporalClient client; + + public MyActivities(ITemporalClient client) => this.client = client; + + [Activity] + public async Task Echo() + { + return "hi"; + } + } +} \ No newline at end of file diff --git a/features/activity/basic_no_workflow_timeout/feature.go b/features/activity/basic_no_workflow_timeout/feature.go index 69b7b5eb..2d45607b 100644 --- a/features/activity/basic_no_workflow_timeout/feature.go +++ b/features/activity/basic_no_workflow_timeout/feature.go @@ -18,14 +18,20 @@ var Feature = harness.Feature{ } func Workflow(ctx workflow.Context) (string, error) { - // Allow 4 retries with no backoff ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{ StartToCloseTimeout: 1 * time.Minute, }) - // Execute activity and return error var result string err := workflow.ExecuteActivity(ctx, Echo).Get(ctx, &result) + if err != nil { + return "", err + } + + ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{ + ScheduleToCloseTimeout: 1 * time.Minute, + }) + err = workflow.ExecuteActivity(ctx, Echo).Get(ctx, &result) return result, err } diff --git a/features/activity/basic_no_workflow_timeout/feature.java b/features/activity/basic_no_workflow_timeout/feature.java index 7333bebc..309041b4 100644 --- a/features/activity/basic_no_workflow_timeout/feature.java +++ b/features/activity/basic_no_workflow_timeout/feature.java @@ -15,13 +15,17 @@ public interface feature extends Feature, SimpleWorkflow { class Impl implements feature { @Override public void workflow() { - // Allow 4 retries with no backoff var activities = activities( feature.class, builder -> builder.setStartToCloseTimeout(Duration.ofMinutes(1))); - // Execute activity activities.echo(); + + var activitiesSched2Close = + activities( + feature.class, builder -> builder.setScheduleToCloseTimeout(Duration.ofMinutes(1))); + + activitiesSched2Close.echo(); } @Override diff --git a/features/activity/basic_no_workflow_timeout/feature.py b/features/activity/basic_no_workflow_timeout/feature.py index da0004a3..412a9631 100644 --- a/features/activity/basic_no_workflow_timeout/feature.py +++ b/features/activity/basic_no_workflow_timeout/feature.py @@ -9,6 +9,10 @@ class Workflow: @workflow.run async def run(self) -> str: + await workflow.execute_activity( + echo, + schedule_to_close_timeout=timedelta(minutes=1), + ) return await workflow.execute_activity( echo, start_to_close_timeout=timedelta(minutes=1), diff --git a/features/activity/basic_no_workflow_timeout/feature.ts b/features/activity/basic_no_workflow_timeout/feature.ts index ca602d6c..a0f9eb89 100644 --- a/features/activity/basic_no_workflow_timeout/feature.ts +++ b/features/activity/basic_no_workflow_timeout/feature.ts @@ -4,8 +4,12 @@ import * as wf from '@temporalio/workflow'; const activities = wf.proxyActivities({ startToCloseTimeout: '1 minute', }); +const activitiesSched2Close = wf.proxyActivities({ + scheduleToCloseTimeout: '1 minute', +}); export async function workflow(): Promise { + await activitiesSched2Close.echo('hello'); return await activities.echo('hello'); }