Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// <auto-generated/>
#pragma warning disable

namespace Internal.Generated.WolverineHandlers
{
// START: OtherThingUpdatedHandlerHandler1764485989
[global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")]
public sealed class OtherThingUpdatedHandlerHandler1764485989 : Wolverine.Runtime.Handlers.MessageHandler
{


public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation)
{
// The actual message body
var thingUpdated = (CoreTests.Persistence.Sagas.ThingUpdated)context.Envelope.Message;

System.Diagnostics.Activity.Current?.SetTag("message.handler", "CoreTests.Persistence.Sagas.OtherThingUpdatedHandler");

// The actual message execution
CoreTests.Persistence.Sagas.OtherThingUpdatedHandler.Handle(thingUpdated);

return System.Threading.Tasks.Task.CompletedTask;
}

}

// END: OtherThingUpdatedHandlerHandler1764485989


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// <auto-generated/>
#pragma warning disable
using Wolverine.Persistence.Sagas;

namespace Internal.Generated.WolverineHandlers
{
// START: StartTrackingHandler203606461
[global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")]
public sealed class StartTrackingHandler203606461 : Wolverine.Runtime.Handlers.MessageHandler
{
private readonly Wolverine.Persistence.Sagas.InMemorySagaPersistor _inMemorySagaPersistor;

public StartTrackingHandler203606461(Wolverine.Persistence.Sagas.InMemorySagaPersistor inMemorySagaPersistor)
{
_inMemorySagaPersistor = inMemorySagaPersistor;
}



public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation)
{
// The actual message body
var startTracking = (CoreTests.Persistence.Sagas.StartTracking)context.Envelope.Message;

// Application-specific Open Telemetry auditing
System.Diagnostics.Activity.Current?.SetTag("Id", startTracking.Id);

// The actual message execution
var outgoing1 = CoreTests.Persistence.Sagas.TrackedThing.Start(startTracking);

_inMemorySagaPersistor.Store<CoreTests.Persistence.Sagas.TrackedThing>(outgoing1);
if (!outgoing1.IsCompleted())
{
_inMemorySagaPersistor.Store<CoreTests.Persistence.Sagas.TrackedThing>(outgoing1);
}

// No unit of work
return System.Threading.Tasks.Task.CompletedTask;
}

}

// END: StartTrackingHandler203606461


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// <auto-generated/>
#pragma warning disable
using Wolverine.Persistence.Sagas;

namespace Internal.Generated.WolverineHandlers
{
// START: ThingUpdatedHandler1830125249
[global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")]
public sealed class ThingUpdatedHandler1830125249 : Wolverine.Runtime.Handlers.MessageHandler
{
private readonly Wolverine.Persistence.Sagas.InMemorySagaPersistor _inMemorySagaPersistor;

public ThingUpdatedHandler1830125249(Wolverine.Persistence.Sagas.InMemorySagaPersistor inMemorySagaPersistor)
{
_inMemorySagaPersistor = inMemorySagaPersistor;
}



public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation)
{
// The actual message body
var thingUpdated = (CoreTests.Persistence.Sagas.ThingUpdated)context.Envelope.Message;

// Application-specific Open Telemetry auditing
System.Diagnostics.Activity.Current?.SetTag("Id", thingUpdated.Id);
if (!System.Guid.TryParse(context.Envelope.SagaId, out System.Guid sagaId)) sagaId = thingUpdated.Id;
if (sagaId == System.Guid.Empty) throw new Wolverine.Persistence.Sagas.IndeterminateSagaStateIdException(context.Envelope);
var trackedThing = _inMemorySagaPersistor.Load<CoreTests.Persistence.Sagas.TrackedThing>(sagaId);
if (trackedThing == null)
{
throw new Wolverine.Persistence.Sagas.UnknownSagaException(typeof(CoreTests.Persistence.Sagas.TrackedThing), sagaId);
}

else
{

// The actual message execution
trackedThing.Handle(thingUpdated, context.Envelope);

// Delete the saga if completed, otherwise update it
if (trackedThing.IsCompleted())
{
_inMemorySagaPersistor.Delete<CoreTests.Persistence.Sagas.TrackedThing>(sagaId);
}

else
{
_inMemorySagaPersistor.Store<CoreTests.Persistence.Sagas.TrackedThing>(trackedThing);
}

// No unit of work
}

return System.Threading.Tasks.Task.CompletedTask;
}

}

// END: ThingUpdatedHandler1830125249


}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.Hosting;
using Wolverine.Attributes;
using Wolverine.Tracking;
using JasperFx.CodeGeneration;
using Xunit;

namespace CoreTests.Persistence.Sagas;
Expand All @@ -18,12 +19,15 @@ public async Task able_to_use_separated_behaviors_with_sagas()
opts.Discovery.DisableConventionalDiscovery()
.IncludeType(typeof(TrackedThing))
.IncludeType(typeof(OtherThingUpdatedHandler));


opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto;
opts.MultipleHandlerBehavior = MultipleHandlerBehavior.Separated;
}).StartAsync();

var id = Guid.NewGuid();

TrackedThing.Updates = 0;

await host.InvokeMessageAndWaitAsync(new StartTracking(id));

var tracked = await host.SendMessageAndWaitAsync(new ThingUpdated(id));
Expand All @@ -32,18 +36,20 @@ public async Task able_to_use_separated_behaviors_with_sagas()

envelopes.Any(x => x.Destination == new Uri("local://coretests.persistence.sagas.trackedthing/")).ShouldBeTrue();
envelopes.Any(x => x.Destination == new Uri("local://coretests.persistence.sagas.otherthingupdatedhandler/")).ShouldBeTrue();

TrackedThing.Updates.ShouldBe(1);
}
}

public record StartTracking(Guid Id);

public record ThingUpdated(Guid Id);


public class TrackedThing : Saga
{
public Guid Id { get; set; }

public int Updates { get; set; }
public static int Updates { get; set; }

public static TrackedThing Start(StartTracking cmd) => new TrackedThing { Id = cmd.Id };

Expand All @@ -61,4 +67,4 @@ public static void Handle(ThingUpdated updated)
{
Debug.WriteLine("Got updated for " + updated.Id);
}
}
}
4 changes: 1 addition & 3 deletions src/Wolverine/Persistence/Sagas/SagaChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ public SagaChain(WolverineOptions options, IGrouping<Type, HandlerCall> grouping
public SagaChain(HandlerCall handlerCall, HandlerGraph handlerGraph, Endpoint[] endpoints) : base(handlerCall, handlerGraph)
{
foreach (var endpoint in endpoints) RegisterEndpoint(endpoint);

var saga = handlerCall;
SagaType = saga.HandlerType;
SagaMethodInfo = saga.Method;

Handlers.Add(handlerCall);

SagaIdMember = DetermineSagaIdMember(MessageType, SagaType, saga.Method);

Expand Down
Loading