Timeout In Memory Repository Saga Instances

144 views
Skip to first unread message

Ben Rogers

unread,
Feb 7, 2013, 4:51:20 PM2/7/13
to masstrans...@googlegroups.com
Hi,
Is it possible to remove instances of sagas after a timeout period? I have three applications working together. If for any reason one is down then the saga instances of another will not be completed and therefore not removed. However I know a saga instance that is working properly will never have to exist more than 20 minutes. Therefore if a saga instance is that old it should be removed. Here is my code.
 
I have a Saga on a Web Application that uses the In Memory Saga Repository
 
MassTransit.Bus.Initialize(sbc =>
{
  sbc.UseMsmq();
  ...
  sbc.Subscribe(subs =>
  {                       
    subs.Saga<ExportWebClientSaga>(new InMemorySagaRepository<ExportWebClientSaga>());
  });
});
 
In my Saga I have configured RemoveWhen to remove the saga if the State is completed
 
static ExportWebClientSaga()
{
  Define(() =>
  {
    Initially(
      When(Response)
        .Then((saga, message) => saga.HandleResponse(message))                           
     );
    During(NextResponse,
      When(Response)
        .Then((saga, message) => saga.HandleResponse(message))
     );
     RemoveWhen(x => x.CurrentState == Completed);
   });
}
 
 
In HandleResponse I programatically set the CurrentState to Completed
 
public virtual void HandleResponse(SymphonyExportResponseMessage message)
{
  ...
  if (message.IsFinalResponse)
    ChangeCurrentState(Completed);
  else if (CurrentState != NextResponse)
    ChangeCurrentState(NextResponse);
}
I was thinking I could do the following for the RemoveWhen expression
 
x => x.CurrentState == Completed || DateTime.Now > x.StartTime.AddMinutes(20)
 
However I think that expression will only run when there is a saga event. Is that right? Is there another way of doing this?
 
Thank you,
 
Regards Ben
 
 

 
 
 
 
 
 
 
 

Chris Patterson

unread,
Feb 7, 2013, 9:31:12 PM2/7/13
to masstrans...@googlegroups.com
You could use the MassTransit-Quartz scheduling to schedule a message in the future to notify the saga to timeout.


 
 

 
 
 
 
 
 
 
 

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/masstransit-discuss/-/LCHaWJ_-pYYJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages