Unschedule Problem

28 views
Skip to first unread message

Namik Baris Idil

unread,
May 17, 2021, 10:16:49 PM5/17/21
to masstransit-discuss
Hello All,

I have a simple Saga State Machine like below.

using System;
using Automatonymous;
using MassTransit;
using OrderService.SagaStateMachines.States;
using Shared.Messages.Commands;

namespace OrderService.SagaStateMachines
{
public class OrderStateMachine :
MassTransitStateMachine<OrderState>
{
public Schedule<OrderState, OrderCompletionTimeoutExpired> OrderCompletionTimeout { get; }

public OrderStateMachine()
{
Event(() => SubmitOrder, x => x.CorrelateById(context => context.Message.OrderId));

Event(() => TimeoutExpired, x => x.CorrelateById(context => context.Message.CorrelationId));

Schedule(() => OrderCompletionTimeout, instance => instance.OrderCompletionTimeoutTokenId,
s => { s.Delay = TimeSpan.FromSeconds(10); });

InstanceState(i => i.CurrentState);

Initially(
When(SubmitOrder)
.Schedule(OrderCompletionTimeout,
context => context.Init<OrderCompletionTimeoutExpired>(new {context.Instance.CorrelationId}))
.TransitionTo(OrderSubmitted)
.Unschedule(OrderCompletionTimeout)
);

DuringAny(When(TimeoutExpired).Finalize());
}

public Event<SubmitOrder> SubmitOrder { get; private set; }

public State OrderSubmitted { get; private set; }

private Event<OrderCompletionTimeoutExpired> TimeoutExpired { get; } = default!;
}
}

My problem is here that, even I unschedule (.Unschedule(OrderCompletionTimeout)) the timeout after receiving SubmitOrder, it still timeout and transit to Final state (DuringAny(When(TimeoutExpired).Finalize())) after 10 seconds. What am I doing here wrong?

Thanks.

Chris Patterson

unread,
May 18, 2021, 11:24:47 AM5/18/21
to masstrans...@googlegroups.com
1st. Why would you unschedule immediately after scheduling? (I'm assuming that just to prove out the issue)
2nd. If you're using transport scheduling, you can't unschedule.
3rd. There is always a chance that even if a scheduled message is unscheduled, it can be delivered (due to latency, timing, etc.)


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/AD0B2EF8-200A-4711-8037-B87EC4F915E5%40popcore.com.

Namik Baris Idil

unread,
May 19, 2021, 2:25:56 PM5/19/21
to masstransit-discuss
Hello,

1st: Yes, only for demonstration purposes
2nd: Yes, I read it also in the document (https://masstransit-project.com/advanced/scheduling/rabbitmq-delayed.html) after I sent the message. I need to read more carefully next time!
3rd: As far as I understand, even if it supports (like Azure Service Bus), it is a bad idea to intervene with messages in the bus directly.

Thanks Chris for the help!

Best,

Barish

Reply all
Reply to author
Forward
0 new messages