Skip to content

Commit a466055

Browse files
committed
Update to use new Semaphore and change name to "Safe"
1 parent be233c9 commit a466055

11 files changed

+23
-24
lines changed

Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Temporalio" Version="1.1.2" />
23-
<PackageReference Include="Temporalio.Extensions.DiagnosticSource" Version="1.1.2" />
24-
<PackageReference Include="Temporalio.Extensions.Hosting" Version="1.1.2" />
25-
<PackageReference Include="Temporalio.Extensions.OpenTelemetry" Version="1.1.2" />
22+
<PackageReference Include="Temporalio" Version="1.2.0" />
23+
<PackageReference Include="Temporalio.Extensions.DiagnosticSource" Version="1.2.0" />
24+
<PackageReference Include="Temporalio.Extensions.Hosting" Version="1.2.0" />
25+
<PackageReference Include="Temporalio.Extensions.OpenTelemetry" Version="1.2.0" />
2626
<!--
2727
Can also reference the SDK downloaded to a local directory:
2828
<ProjectReference Include="$(MSBuildThisFileDirectory)..\temporal-sdk-dotnet\src\Temporalio\Temporalio.csproj" />

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Prerequisites:
1515
* [ActivityHeartbeatingCancellation](src/ActivityHeartbeatingCancellation) - How to use heartbeating and cancellation handling in an activity.
1616
* [ActivitySimple](src/ActivitySimple) - Simple workflow that runs simple activities.
1717
* [ActivityWorker](src/ActivityWorker) - Use .NET activities from a workflow in another language.
18-
* [AtomicMessageHandlers](src/AtomicMessageHandlers) - Use `SemaphoreSlim` to ensure operations are atomically processed in a workflow.
1918
* [AspNet](src/AspNet) - Demonstration of a generic host worker and an ASP.NET workflow starter.
2019
* [ClientMtls](src/ClientMtls) - How to use client certificate authentication, e.g. for Temporal Cloud.
2120
* [ContextPropagation](src/ContextPropagation) - Context propagation via interceptors.
2221
* [DependencyInjection](src/DependencyInjection) - How to inject dependencies in activities and use generic hosts for workers
2322
* [Encryption](src/Encryption) - End-to-end encryption with Temporal payload codecs.
2423
* [Mutex](src/Mutex) - How to implement a mutex as a workflow. Demonstrates how to avoid race conditions or parallel mutually exclusive operations on the same resource.
2524
* [Polling](src/Polling) - Recommended implementation of an activity that needs to periodically poll an external resource waiting its successful completion.
25+
* [SafeMessageHandlers](src/SafeMessageHandlers) - Use `Semaphore` to ensure operations are atomically processed in a workflow.
2626
* [Saga](src/Saga) - Demonstrates how to implement a saga pattern.
2727
* [Schedules](src/Schedules) - How to schedule workflows to be run at specific times in the future.
2828
* [SignalsQueries](src/SignalsQueries) - A loyalty program using Signals and Queries.

TemporalioSamples.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemporalioSamples.WorkflowU
5555
EndProject
5656
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemporalioSamples.ContextPropagation", "src\ContextPropagation\TemporalioSamples.ContextPropagation.csproj", "{7B797D20-485F-441D-8E71-AF7E315FA9CF}"
5757
EndProject
58-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemporalioSamples.AtomicMessageHandlers", "src\AtomicMessageHandlers\TemporalioSamples.AtomicMessageHandlers.csproj", "{5E497499-F87C-4DC6-B5DC-F508F31EA172}"
58+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemporalioSamples.SafeMessageHandlers", "src\SafeMessageHandlers\TemporalioSamples.SafeMessageHandlers.csproj", "{FAF5984A-5B1C-4686-B056-A4F2AC0E8EB7}"
5959
EndProject
6060
Global
6161
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -151,10 +151,10 @@ Global
151151
{7B797D20-485F-441D-8E71-AF7E315FA9CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
152152
{7B797D20-485F-441D-8E71-AF7E315FA9CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
153153
{7B797D20-485F-441D-8E71-AF7E315FA9CF}.Release|Any CPU.Build.0 = Release|Any CPU
154-
{5E497499-F87C-4DC6-B5DC-F508F31EA172}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
155-
{5E497499-F87C-4DC6-B5DC-F508F31EA172}.Debug|Any CPU.Build.0 = Debug|Any CPU
156-
{5E497499-F87C-4DC6-B5DC-F508F31EA172}.Release|Any CPU.ActiveCfg = Release|Any CPU
157-
{5E497499-F87C-4DC6-B5DC-F508F31EA172}.Release|Any CPU.Build.0 = Release|Any CPU
154+
{FAF5984A-5B1C-4686-B056-A4F2AC0E8EB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
155+
{FAF5984A-5B1C-4686-B056-A4F2AC0E8EB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
156+
{FAF5984A-5B1C-4686-B056-A4F2AC0E8EB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
157+
{FAF5984A-5B1C-4686-B056-A4F2AC0E8EB7}.Release|Any CPU.Build.0 = Release|Any CPU
158158
EndGlobalSection
159159
GlobalSection(SolutionProperties) = preSolution
160160
HideSolutionNode = FALSE
@@ -184,6 +184,6 @@ Global
184184
{B79F07F7-3429-4C58-84C3-08587F748B2D} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
185185
{B3DB7B8C-7BD3-4A53-A809-AB6279B1A630} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
186186
{7B797D20-485F-441D-8E71-AF7E315FA9CF} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
187-
{5E497499-F87C-4DC6-B5DC-F508F31EA172} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
187+
{FAF5984A-5B1C-4686-B056-A4F2AC0E8EB7} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
188188
EndGlobalSection
189189
EndGlobal

src/AspNet/Worker/TemporalioSamples.AspNet.Worker.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<UserSecretsId>dotnet-AspNet-Worker-a95eda12-24b8-4044-81a5-4d4d3f959742</UserSecretsId>
5+
<PublishTrimmed>true</PublishTrimmed>
56
</PropertyGroup>
67

78
<ItemGroup>

src/AtomicMessageHandlers/ClusterManagerActivities.cs renamed to src/SafeMessageHandlers/ClusterManagerActivities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace TemporalioSamples.AtomicMessageHandlers;
1+
namespace TemporalioSamples.SafeMessageHandlers;
22

33
using Microsoft.Extensions.Logging;
44
using Temporalio.Activities;

src/AtomicMessageHandlers/ClusterManagerWorkflow.workflow.cs renamed to src/SafeMessageHandlers/ClusterManagerWorkflow.workflow.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
namespace TemporalioSamples.AtomicMessageHandlers;
1+
namespace TemporalioSamples.SafeMessageHandlers;
22

33
using Microsoft.Extensions.Logging;
44
using Temporalio.Exceptions;
55
using Temporalio.Workflows;
66

77
[Workflow]
8-
public sealed class ClusterManagerWorkflow : IDisposable
8+
public class ClusterManagerWorkflow
99
{
1010
public record State
1111
{
@@ -29,7 +29,7 @@ public record Result(
2929
int MaxAssignedNodes,
3030
int NumAssignedNodes);
3131

32-
private readonly SemaphoreSlim nodesLock = new(1, 1);
32+
private readonly Semaphore nodesLock = new(1);
3333
private readonly int maxHistoryLength;
3434
private readonly TimeSpan sleepInterval;
3535

@@ -167,8 +167,6 @@ await Workflow.ExecuteActivityAsync(
167167
}
168168
}
169169

170-
public void Dispose() => nodesLock.Dispose();
171-
172170
private int NumAssignedNodes =>
173171
CurrentState.Nodes.Count(kvp => kvp.Value is { } val && val != "BAD!");
174172

src/AtomicMessageHandlers/Program.cs renamed to src/SafeMessageHandlers/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Temporalio.Api.Enums.V1;
33
using Temporalio.Client;
44
using Temporalio.Worker;
5-
using TemporalioSamples.AtomicMessageHandlers;
5+
using TemporalioSamples.SafeMessageHandlers;
66

77
// Create a client to localhost on default namespace
88
using var loggerFactory = LoggerFactory.Create(builder =>

src/AtomicMessageHandlers/README.md renamed to src/SafeMessageHandlers/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Atomic Message Handlers
1+
# Safe Message Handlers
22

3-
This sample shows a workflow using `SemaphoreSlim` to atomically process certain blocks of workflow code to prevent data
4-
race issues. The sample code demonstrates assigning cluster nodes to jobs atomically.
3+
This sample shows a workflow using `Temporalio.Workflows.Semaphore` to atomically process certain blocks of workflow
4+
code to prevent data race issues. The sample code demonstrates assigning cluster nodes to jobs atomically.
55

66
To run, first see [README.md](../../README.md) for prerequisites. Then, run the following from this directory
77
in a separate terminal to start the worker:

tests/AtomicMessageHandlers/ClusterManagerWorkflowTests.cs renamed to tests/SafeMessageHandlers/ClusterManagerWorkflowTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
namespace TemporalioSamples.AtomicMessageHandlers;
1+
namespace TemporalioSamples.Tests.SafeMessageHandlers;
22

33
using Temporalio.Client;
44
using Temporalio.Worker;
5-
using TemporalioSamples.Tests;
5+
using TemporalioSamples.SafeMessageHandlers;
66
using Xunit;
77
using Xunit.Abstractions;
88

0 commit comments

Comments
 (0)