Long-running ASP.NET tasks

后端 未结 4 2179
猫巷女王i
猫巷女王i 2020-11-27 23:10

I know there\'s a bunch of APIs out there that do this, but I also know that the hosting environment (being ASP.NET) puts restrictions on what you can reliably do in a separ

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 23:46

    Use a simple background tasks / jobs framework like Hangfire and apply these best practice principals to the design of the rest of your solution:

    • Keep all actions as small as possible; to achieve this, you should-
    • Divide long running jobs into batches and queue them (in a Hangfire queue or on a bus of another sort)
    • Make sure your small jobs (batched parts of long jobs) are idempotent (have all the context they need to run in any order). This way you don't have to use a quete which maintains a sequence; because then you can
    • Parallelise the execution of jobs in your queue depending on how many nodes you have in your web server farm. You can even control how much load this subjects your farm to (as a trade off to servicing web requests). This ensures that you complete the whole job (all batches) as fast and as efficiently as possible, while not compromising your cluster from servicing web clients.

提交回复
热议问题