简体   繁体   中英

Running Background tasks inside Service fabric - ASP.NET Core HostedService or use StatelessService.RunAsync()?

We have microservices running inside Azure Service fabric and we have a background task that needs to run once every 15 minutes to do some DB related operations. I see 2 options.

  1. Use the StatelessService.RunAsync method and implement the background task under one of the relavant microservices.

  2. Implement the logic using HostedService and do services.AddHostedService inside ConfigureServices method in startup.cs of the relevant microservice.

What's the difference and which way would be preferred?

Thanks

Options:

  • Reliable actor timers
  • Reliable actor reminders
  • .NET Hosted services: If you have a multi node cluster and you implement a hosted service it will run on each node where the Service is running. So only do this if you are okay with multiple invocations.
  • Third party library for job sheduling like Hangfire , Quartz.Net , Jobbr , ... (These might have issues with the service fabric runtime)

Have a look at this blog for reliable actors with reminders

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM