I want to build on this question.
So far I have got a way to process jobs in parallel. I'm running this in a console app. I get say 50 jobs from db, process them using TPL DataFlow
and so far so good. But I realized that if there is a job that takes an hour to process and rest of the jobs get done in 15 minutes, the console application will keep going for an hour without processing any further jobs. I can't change this to a windows service so I have to make the console application process new jobs coming in, may be check every 15 minutes.
I could kick off a timer that checks for new jobs every 15 minutes. If there is any new job in the db, I will need to add to the buffer block
so actionblock
can process it. The problem is that after you add the first 50 jobs, you have to call complete and completion.wait for buffer and action blocks. So I can't add anymore new jobs to the existing buffer.
I could check the current actionblock's
isCompleted property and then create another combination of buffer/actionblock
dynamically. Basically the condition is if the current actionblock
is still going, check for new jobs on a timer
and create a new buffer/actionblock
combination. This is what I plan on doing. But before I go down that path, is there another approach I can take to handle this?