c# - How to queue background tasks in ASP.NET Web API -
i have webapi designed process reports in queue fashion. steps application takes follows:
receive content map content object , place queue poll pending items in queue process items in queue 1 @ timei thinking utilize entity framework create database of queued items, such as:
public class efbatchitem { [key] public string batchid { get; set; } public datetime datecreated { get; set; } public datetime datecompleted { get; set; } public string batchitem { get; set; } public batchstatus status { get; set; } }
my question - there more efficient way, using nservicebus, blockingcollection or concurrentqeueue, poll database , pull out pending items 1 one? have not used queues before.
one thought create queue of tasks, , on separate thread process pending tasks. similar most efficient way process queue threads want ensure going efficient route.
edit: big question have here best way display progress user. 1 time user submits content, gets taken new page , can view status batch identifier. msmq necessary, or nservicebus, in order notify user? seems variation of request/acknowledge/push paradigm?
imho, asp.net web api application shouldn't run background tasks itself. should responsible receive request, stick within queue (as indicated) , homecoming response indicating success or failure of received message. can utilize variety of messaging systems such rabbitmq approach.
as notification, have few options. can have endpoint client can check whether processing completed or not. alternatively, provide streaming api endpoint client can subscribe to. way, client doesn't have poll server; server can notify clients connected. asp.net web api has great way of doing this. next blog post explains how:
native html5 force notifications asp.net web api , knockout.jsyou can consider signalr type of server client notifications.
the reason why background tasks hard asp.net web api application you're responsible maintain appdomain alive. hassle when hosting under iis. next blog posts explains mean:
returning asp.net requests the dangers of implementing recurring background tasks in asp.net c# asp.net-web-api queue
No comments:
Post a Comment