I am attempting to create a long running job to be used in Azure. I would like to be able to run multiple instances of this job if I needed it.
I was thinking of seperating the primary functionality into two different webjobs. With one job called "the brain". while the other job(s) would be called the worker.
Brain would be in charge of actually knowing what jobs needs to get run and put them into the Azure storage ques that would be listened to by worker jobs. I envision a few different queues and a few different workers handling different tasks listening to queues.
The job list is stored in a regular database with values about when it should be run next and the type of job it is. Brain will periodically look to the database and get the next job that needs to get run. Pass it off to a queue for a worker webjob to handle and either write back to the database if the job is regularly run or just update the status in the database.
Question: Given this setup how would you actually handle getting the next job to be run (what is next is based on a date and time) and setting it's status to 'processing' (so it is not picked twice) in such a way that there is not chance for it to be picked up twice (two instances of Brain running)? I am using EF6 in this case. Is there a way to get the record and update it before anyone else could do that on the database?
A shorter version of the question is How can I pull and update a record and be sure it is not modified while the process is happening using EF6?
Should I be using a different type of job management? Is there a good tutorial available on a better way to do this?