How to trigger the execution of the compensation flow for the activities used within an Automatonymous state...











up vote
0
down vote

favorite












My activities throw exceptions from time to time during the execution, so I've implemented the Faulted methods of Activity<TInstance> to handle that, discarding the changes made in the Execute method. I thought that there's some wiring underneath in Automatonymous that makes it so that the Faulted method executes when the Execute method throws an exception and then calls the Faulted methods for the activities that were executed already. It turns out that there's no such thing, as my Faulted methods are never executed.



Should I call those myself in a try/catch block instead? I could produce the BehaviorExceptionContextProxy based on BehaviorContext and the exception thrown. The only next Behavior I could pass would be the one inserted into that Activity's Execute method, but logically that means I'm compensating in the wrong direction as that next Behavior is actually to be executed after this one succeeds, so I'd compensate too much.



I also tried to use the Catch in the state machine, which does handle the exception, however, I couldn't find any way to start the execution of the compensation flow for the activity that failed when I only have the ExceptionActivityBinder present.



Is there any good way to trigger the compensation flow of the activities?










share|improve this question






















  • Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
    – Alexey Zimarev
    Nov 22 at 15:14










  • Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
    – Slowacki
    Nov 22 at 15:23












  • I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
    – Alexey Zimarev
    Nov 22 at 15:33










  • You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
    – Slowacki
    Nov 22 at 15:40

















up vote
0
down vote

favorite












My activities throw exceptions from time to time during the execution, so I've implemented the Faulted methods of Activity<TInstance> to handle that, discarding the changes made in the Execute method. I thought that there's some wiring underneath in Automatonymous that makes it so that the Faulted method executes when the Execute method throws an exception and then calls the Faulted methods for the activities that were executed already. It turns out that there's no such thing, as my Faulted methods are never executed.



Should I call those myself in a try/catch block instead? I could produce the BehaviorExceptionContextProxy based on BehaviorContext and the exception thrown. The only next Behavior I could pass would be the one inserted into that Activity's Execute method, but logically that means I'm compensating in the wrong direction as that next Behavior is actually to be executed after this one succeeds, so I'd compensate too much.



I also tried to use the Catch in the state machine, which does handle the exception, however, I couldn't find any way to start the execution of the compensation flow for the activity that failed when I only have the ExceptionActivityBinder present.



Is there any good way to trigger the compensation flow of the activities?










share|improve this question






















  • Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
    – Alexey Zimarev
    Nov 22 at 15:14










  • Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
    – Slowacki
    Nov 22 at 15:23












  • I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
    – Alexey Zimarev
    Nov 22 at 15:33










  • You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
    – Slowacki
    Nov 22 at 15:40















up vote
0
down vote

favorite









up vote
0
down vote

favorite











My activities throw exceptions from time to time during the execution, so I've implemented the Faulted methods of Activity<TInstance> to handle that, discarding the changes made in the Execute method. I thought that there's some wiring underneath in Automatonymous that makes it so that the Faulted method executes when the Execute method throws an exception and then calls the Faulted methods for the activities that were executed already. It turns out that there's no such thing, as my Faulted methods are never executed.



Should I call those myself in a try/catch block instead? I could produce the BehaviorExceptionContextProxy based on BehaviorContext and the exception thrown. The only next Behavior I could pass would be the one inserted into that Activity's Execute method, but logically that means I'm compensating in the wrong direction as that next Behavior is actually to be executed after this one succeeds, so I'd compensate too much.



I also tried to use the Catch in the state machine, which does handle the exception, however, I couldn't find any way to start the execution of the compensation flow for the activity that failed when I only have the ExceptionActivityBinder present.



Is there any good way to trigger the compensation flow of the activities?










share|improve this question













My activities throw exceptions from time to time during the execution, so I've implemented the Faulted methods of Activity<TInstance> to handle that, discarding the changes made in the Execute method. I thought that there's some wiring underneath in Automatonymous that makes it so that the Faulted method executes when the Execute method throws an exception and then calls the Faulted methods for the activities that were executed already. It turns out that there's no such thing, as my Faulted methods are never executed.



Should I call those myself in a try/catch block instead? I could produce the BehaviorExceptionContextProxy based on BehaviorContext and the exception thrown. The only next Behavior I could pass would be the one inserted into that Activity's Execute method, but logically that means I'm compensating in the wrong direction as that next Behavior is actually to be executed after this one succeeds, so I'd compensate too much.



I also tried to use the Catch in the state machine, which does handle the exception, however, I couldn't find any way to start the execution of the compensation flow for the activity that failed when I only have the ExceptionActivityBinder present.



Is there any good way to trigger the compensation flow of the activities?







masstransit saga automatonymous






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 13:42









Slowacki

121311




121311












  • Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
    – Alexey Zimarev
    Nov 22 at 15:14










  • Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
    – Slowacki
    Nov 22 at 15:23












  • I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
    – Alexey Zimarev
    Nov 22 at 15:33










  • You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
    – Slowacki
    Nov 22 at 15:40




















  • Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
    – Alexey Zimarev
    Nov 22 at 15:14










  • Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
    – Slowacki
    Nov 22 at 15:23












  • I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
    – Alexey Zimarev
    Nov 22 at 15:33










  • You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
    – Slowacki
    Nov 22 at 15:40


















Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
– Alexey Zimarev
Nov 22 at 15:14




Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
– Alexey Zimarev
Nov 22 at 15:14












Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
– Slowacki
Nov 22 at 15:23






Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
– Slowacki
Nov 22 at 15:23














I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
– Alexey Zimarev
Nov 22 at 15:33




I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
– Alexey Zimarev
Nov 22 at 15:33












You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
– Slowacki
Nov 22 at 15:40






You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
– Slowacki
Nov 22 at 15:40














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.



When an activity throws an exception, the Faulted method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted method of those activities just calls the next activity in the behavior.



A Catch activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).



Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.






share|improve this answer





















  • Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
    – Slowacki
    Nov 29 at 17:30













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432308%2fhow-to-trigger-the-execution-of-the-compensation-flow-for-the-activities-used-wi%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.



When an activity throws an exception, the Faulted method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted method of those activities just calls the next activity in the behavior.



A Catch activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).



Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.






share|improve this answer





















  • Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
    – Slowacki
    Nov 29 at 17:30

















up vote
1
down vote



accepted










An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.



When an activity throws an exception, the Faulted method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted method of those activities just calls the next activity in the behavior.



A Catch activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).



Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.






share|improve this answer





















  • Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
    – Slowacki
    Nov 29 at 17:30















up vote
1
down vote



accepted







up vote
1
down vote



accepted






An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.



When an activity throws an exception, the Faulted method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted method of those activities just calls the next activity in the behavior.



A Catch activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).



Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.






share|improve this answer












An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.



When an activity throws an exception, the Faulted method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted method of those activities just calls the next activity in the behavior.



A Catch activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).



Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 at 3:40









Chris Patterson

8,2722329




8,2722329












  • Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
    – Slowacki
    Nov 29 at 17:30




















  • Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
    – Slowacki
    Nov 29 at 17:30


















Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
– Slowacki
Nov 29 at 17:30






Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
– Slowacki
Nov 29 at 17:30




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432308%2fhow-to-trigger-the-execution-of-the-compensation-flow-for-the-activities-used-wi%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu