These are chat archives for petabridge/akka-bootcamp

15th
Aug 2015
Ethan Lee Kon Keong
@konkeong
Aug 15 2015 02:08
I am sorry to bother someone, I didn't get my bootcamp lesion 1.3 on Friday. I have 1.1 on Wed, 1.2 on Thurs, and 1.4 on Sat (just now). How can I retrieve Lesson 1.3?
Ethan Lee Kon Keong
@konkeong
Aug 15 2015 10:12
Thank you for the info.
Michael Dadashyan
@mebymyself
Aug 15 2015 20:10
Hi, . I am rewriting some legacy code and trying to use Akka.net for some parts. I have an Actor that pulls some list of IDs from database and in loop calls some external api to get some data. sometime the call fails because of network issues and retrying is usually helps. But sometime It fails for different reason. Unfortunately the api throw same exception in both cases. I need help with setting up Supervisor strategy for that Actor so if specific exception is thrown it retries let say 3 times and if it does not help - mark that record as not processable and move forward. Is it possible to achieve?
Bartosz Sypytkowski
@Horusiath
Aug 15 2015 20:12
@mebymyself are you calling an external service asynchronously?
Michael Dadashyan
@mebymyself
Aug 15 2015 20:25
yes. something like this:
protected override void OnReceive(object message)
{
    if (message is CollectData)
    {
        CollectDataAsync( message.Ids);
    }
}

private async void CollectDataAsync(List<int> ids)
{
    foreach (var id in ids)
    {
        var data = await Program.ApiClient.GetData(id);
    }
}
Bartosz Sypytkowski
@Horusiath
Aug 15 2015 20:42
at this point you're just siliently ingore any exceptions and in worst case scenario, you may potentially run out of memory, since you're not tracking async code execution (you have async method, that doesn't return task and call it from synchronous code), just spawning tasks
Michael Dadashyan
@mebymyself
Aug 15 2015 20:44
@Horusiath, What is the recommended way of handling async calls from an Actor?
Bartosz Sypytkowski
@Horusiath
Aug 15 2015 20:44
if you change CollectDataAsyncmethod signature to return Task, in it's invocation inside OnReceive method you may use PipeTo method to send a message to choosen actor when task completes
protected override void OnReceive(object message)
{
    if (message is CollectData)
    {
        CollectDataAsync(message.Ids)
            .ContinueWith(task => task.IsFaulted ? new DataCollectionSuccess() : new DataCollectionFailure())
            .PipeTo(Self);
    }
    else if (message is DataCollectionSuccess)
    {
        // handle CollectDataAsync success
    }
    else if (message is DataCollectionFailure)
    {
        // handle CollectDataAsync failure
    }
}
Michael Dadashyan
@mebymyself
Aug 15 2015 20:50
@Horusiath . Thanks - lets me try it out. I might bother you again :)