Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/22/08 21:16:39 (16 years ago)
Author:
gkronber
Message:

worked on unification of agents and runs (ticket #188)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs

    r390 r392  
    4545    private object queueLock = new object();
    4646    private Queue<Job> jobQueue;
     47    private AutoResetEvent runningJobs = new AutoResetEvent(false);
    4748
    4849    public RunScheduler(Database database, JobManager jobManager) {
     
    8081        lock(queueLock) {
    8182          jobQueue.Enqueue(job);
     83          runningJobs.Set();
    8284        }
    8385      }
     
    8789      try {
    8890        while(true) {
    89           int runningJobs;
    90           lock(queueLock) runningJobs = jobQueue.Count;
    91           if(runningJobs==0) Thread.Sleep(1000); // TASK: replace with waithandle
     91          Job job = null;
     92          lock(queueLock) if(jobQueue.Count > 0) job = jobQueue.Dequeue();
     93          if(job == null) runningJobs.WaitOne();
    9294          else {
    93             Job job;
    94             lock(queueLock) {
    95               job = jobQueue.Dequeue();
    96             }
    9795            job.WaitHandle.WaitOne();
    9896            job.WaitHandle.Close();
    9997            lock(remoteCommLock) {
    100               jobManager.EndExecuteOperation(job.Operation);
    101               database.UpdateAgent(job.AgentId, ProcessStatus.Finished);
     98              try {
     99                jobManager.EndExecuteOperation(job.Operation);
     100                database.UpdateAgent(job.AgentId, ProcessStatus.Finished);
     101              } catch(JobExecutionException ex) {
     102                database.UpdateAgent(job.AgentId, ProcessStatus.Error);
     103              }
    102104            }
    103105          }
Note: See TracChangeset for help on using the changeset viewer.