Exemple #1
0
        public static async Task <JobItem> DeqeueueJobItemAsync(Guid workerID)
        {
            await jobLocker.WaitAsync();

            if (jobQueue.Count == 0)
            {
                jobLocker.Release();
                return(null);
            }

            JobItem job = jobQueue.Dequeue();

            jobLocker.Release();

            job.heartbeat = DateTime.UtcNow;
            job.workerID  = workerID;

            await workerLocker.WaitAsync();

            if (!workers.ContainsKey(workerID))
            {
                workers.Add(workerID, new WorkerInfo(workerID));
            }
            workers[workerID].AddJobItem(job);
            workerLocker.Release();

            return(job);
        }
Exemple #2
0
        public static async Task QueueJobItemAsync(JobItem jobItem)
        {
            await jobLocker.WaitAsync();

            jobQueue.Enqueue(jobItem);
            jobLocker.Release();
        }
Exemple #3
0
        public static async Task <JobItem> RemoveJobForResponse(Guid workerID, Guid jobID)
        {
            await workerLocker.WaitAsync();

            if (!workers.ContainsKey(workerID))
            {
                workerLocker.Release();
                return(null);
            }

            if (!workers[workerID].JobList.ContainsKey(jobID))
            {
                workerLocker.Release();
                return(null);
            }

            JobItem jobItem = workers[workerID].JobList[jobID];

            workers[workerID].JobList.Remove(jobID);
            workerLocker.Release();

            return(jobItem);
        }
 public void AddJobItem(JobItem job)
 {
     JobList.Add(job.job.ID, job);
 }