Can a saga has multiple timeout handlers - .net-core

We have implemented a saga that has a timeout method and worked as expected. Later we wanted to add one more timeout method. So, I have added it to the same saga but the second timeout is not getting called. These two messages will be called at a time. Can we have two IHandlerTimeouts in a single saga?
public class SagaPolicy1 : Saga<SagaPolicyData>,
IAmStartedByMessages<OrderPlacedCommand>,
IHandleTimeouts<TimoutMsg1>,//timespan 20min
IHandleTimeouts<TimoutMsg2>
await RequestTimeout<TimoutMsg1>(context, TimeSpan.FromSeconds(1200));
await RequestTimeout<TimoutMsg2>(context, TimeSpan.FromSeconds(360));

The short answer is yes. The documentation explicitly calls it out. Remember that a timeout can be queued after its saga has been completed (using MarkAsComplete()). Because a timeout is tied to a specific saga instance, it will be ignored once the saga instance is completed.

Related

grpc client completion queue not shutting down

My code performs the following:
1)Create grpc channel
2)start monitoring completion queue in a different thread
3)Issue shutdown on completion queue
After executing step 3, I expect "(cq.Next(&tag, &ok)" to return false as there are no pending events with above 3 steps. But it is observed that "(cq.Next(&tag, &ok)" never returns false. Please let me know if I am missing something.
Thanks,
Ikshu
In order to get channel state notification, a tag was being added to the queue and that use to always post some events. so the cq->next() never returned false. I fixed this issue by achieving same functionality by using already existing standard API for channel state. So closing the bug.

gRPC Java - Listening for successful calls on server

I am looking for a way to capture when a call is completed on the server and no errors were thrown.
I understand that SimpleForwardingServerCallListener exists, however,onComplete is called when an exception is thrown.
My use case is for transaction management.
Yes, it currently only triggers onComplete(). There is a bug filed for that. If it's fixed, you can probably get onCancel() instead.
For now, you can wrap the ServerCall with SimpleForwardingServerCall in your ServerInterceptor, and override close(). If the RPC ends successfully, OK will be passed to close().

How to have the same execution id in logs on Cloud Functions for Firebase

There's multiple executions happening interleaved/concurrently in firebase. The log id changes when new execution happens and the old execution id is forgotten. So the execution id moves forward only. When the old function resumes, it uses new execution id. Is there a way to achieve old execution id for old function & new execution id for new function.
Workflow:
Lets say Function1 & Function2 are diffrent triggers of same function.
1. Function1 does some db reads and do http requests. This returns an http promise - This takes some time(maybe some ms). Lets assume its execution-id from log is 154690519665944.
2. Function2 get triggered while function1 was waiting. function2 gets execution-id 154690574405903. function2 also does same thing and waits for http response.
3. Function1 resumes and it got http response and while logging it uses another execution-id 154694739233261 in log.
What happened to execution-id 154690519665944 ?
Since there's multiple triggers happening simultaneously, the only way to find whether a function completed successfully is to check logs. So by using execution-id as the filter, I could have find whether the function executed successfully or not. But because firebase changes execution-id randomly, I guess I have to find another solution.
PS: There's an update call which will trigger the same function. Does that change the parent function execution-id ?
Without seeing your code or complete logs, I don't think a definitive answer can be provided.
However, it sounds like the question you're asking is how can you keep data in memory across asynchronous transactions. Regardless of Firebase or not, you basically have two options:
commit that data to the database during the first part of the
transaction and then retrieve it in the second part
pass the data
from the first part to the second part so that it already has it.
You seem to be relying on the execution-id, so I would recommend taking the latter approach and passing that id along as part the input to your httprequest and having the server your calling return it in its response.

RxJava retry based on logic

Here is the case, I have an API call using Retrofit that might fail due to a network error. If it fails we will show an error message with a retry button. When the user presses the retry button we need to retry the latest Observable again.
Possible Solutions:
Retry: Retry should be used before subscribing to the observable and it will immediately resubscribe again if an error happens and that is what I don't want, I need to resubscribe only if the user pressed the Retry button.
RetryWhen: It Will keep trying as you emit items until you emit an Observable error then it will stop. Same issue here, I need to not start the retry process unless the user decides to.
Resubscribe to the same Observable: This solution will start emitting the Observable items, the problem with this is that we are using the cache operator, so if one Observable failed, we got the failed item cached and when we do subscribe again, we got the same error again.
Are there any other solutions to go with?
You can go with retryWhen, which parameter - Func1 - returns an Observable which indicates when a retry should happen. For example :
PublishSubject<Object> retryButtonClicked = PublishSubject.create();
Observable
.error(new RuntimeException())
.doOnError(throwable -> System.out.println("error"))
.retryWhen(observable -> observable.zipWith(retryButtonClicked, (o, o2) -> o))
.subscribe();
retryButtonClicked.onNext(new Object());
every time retryButtonClicked emmits an event, Observable will be retried
Here's also an example - https://gist.github.com/benjchristensen/3363d420607f03307dd0

How can I execute a callback after a set of asynchronous service calls complete?

In Flex, I'm making a set of asynchronous calls:
service.method1.send().addResponder(responder1);
service.method2.send().addResponder(responder2);
service.method3.send().addResponder(responder3);
I want to execute some code after all of these service calls have returned (either success or failure, I don't care which). How can I do this?
Implement a CallResponder that will monitor the results from each responder & increment a variable in the listener after each result. When the variable hits three, execute some code.

Resources