0

I am very new to Azure Service Fabric.

My scenario is that I have a long-running service that I need to launch/stop multiple instances dynamically, and the launch should be non-block. Each of the instance will process 1 data entry independently. For example:

Say I have a weather service that keeps pulling weather data for each city, and is long-running. And I have a list of cities that can change. So, I want to do the following thing:

var weatherSvcList = new List...
var currentCities = [];
while (true) 
{
    var newCities = FetchCities();

    var addedCities = newCities.Except(currentCities);
    weatherSvcList  = LaunchSvc(addedCities); // launch and return, non-blocking

    var removedCities = currentCities.Except(newCities);
    weatherSvcList  = StopSvc(removedCities);

    weatherSvcList  = RelaunchErrorSvc(cities);

    currentCities = newCities;
}

I've looked into Actor model, but seems like Actors are not suited for long-running task, and also it's hard to start/stop them. Any idea what service/programming model I should use?

Nam Ngo
  • 253
  • 2
  • 11

1 Answers1

0

Consider using a task queue here.

When called, the Weather Service would en-queue a task to pull weather data. It would also run an infinite loop (RunAsync), this loop de-queues and executes tasks.

This way the service calls will return quickly, while the work is performed in the background.

Some code for inspirational purposes here.

LoekD
  • 11,402
  • 17
  • 27
  • Thanks for the solution. I'll check it out tomorrow morning. Happy thanksgiving! – Nam Ngo Nov 24 '17 at 08:09
  • but what service would be running on the background to de-queue the messages and process them in a infinite loop? – Nam Ngo Nov 25 '17 at 01:31