Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/21/11 21:50:39 (14 years ago)
Author:
ascheibe
Message:

#1233

  • fixed job pause bug... again
  • general Executor improvements
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs

    r5778 r5782  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    3536    private bool wasJobAborted = false;
    3637    public Core Core { get; set; }
     38    private Semaphore pauseStopSem = new Semaphore(0, 1);
    3739
    3840    private Exception currentException;
     
    8486
    8587    public void Pause() {
    86       Job.Pause();
    87 
     88      if (Job == null) {
     89        throw new InvalidStateException("Job is null");
     90      }
     91
     92      if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
     93        try {
     94          Job.Pause();
     95          //we need to block the pause...
     96          pauseStopSem.WaitOne();
     97        }
     98        catch (Exception ex) {
     99          SlaveClientCom.Instance.ClientCom.LogMessage("Error pausing job:" + ex.ToString());
     100        }
     101      }
    88102    }
    89103
    90104    public void Stop() {
     105      if (Job == null) {
     106        throw new InvalidStateException("Job is null");
     107      }
    91108      wasJobAborted = true;
     109
    92110      if ((ExecutionState == ExecutionState.Started) || (ExecutionState == ExecutionState.Paused)) {
    93         Job.Stop();
    94       } else {
    95         Job_JobStopped(this, EventArgs.Empty);
     111        try {
     112          Job.Stop();
     113          pauseStopSem.WaitOne();
     114        }
     115        catch (Exception ex) {
     116          SlaveClientCom.Instance.ClientCom.LogMessage("Error stopping job:" + ex.ToString());
     117        }
    96118      }
    97119    }
     
    103125      Job.WaitForChildJobs += new EventHandler(Job_WaitForChildJobs);
    104126      Job.DeleteChildJobs += new EventHandler(Job_DeleteChildJobs);
     127      Job.JobPaused += new EventHandler(Job_JobPaused);
    105128    }
    106129
     
    111134      Job.WaitForChildJobs -= new EventHandler(Job_WaitForChildJobs);
    112135      Job.DeleteChildJobs -= new EventHandler(Job_DeleteChildJobs);
     136      Job.JobPaused -= new EventHandler(Job_JobPaused);
    113137    }
    114138
     
    159183    private void Job_JobStopped(object sender, EventArgs e) {
    160184      if (wasJobAborted) {
    161         Core.EnqueueExecutorMessage(Core.KillAppDomain, JobId);
     185        pauseStopSem.Release();
    162186      } else {
     187        //it's a clean and finished job, so send it
    163188        Core.EnqueueExecutorMessage(Core.SendFinishedJob, JobId);
    164189      }
     
    171196
    172197      if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
    173         try { Job.Stop(); }
    174         catch { }
     198        try {
     199          Job.Stop();
     200          wasJobAborted = true;
     201          pauseStopSem.WaitOne();
     202        }
     203        catch (Exception ex) {
     204          SlaveClientCom.Instance.ClientCom.LogMessage("Error stopping job:" + ex.ToString());
     205        }
    175206      }
    176207
     
    178209    }
    179210
     211
    180212    public JobData GetPausedJob() {
    181       if (Job == null) {
    182         throw new InvalidStateException("Job is null");
    183       }
    184 
    185       if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
    186         try { Job.Pause(); }
    187         catch { }
    188       }
    189 
     213      if (Job.ExecutionState != HeuristicLab.Core.ExecutionState.Paused) {
     214        throw new Exception("Executor: Job has to be paused before fetching results.");
     215      }
    190216      return GetJob();
     217    }
     218
     219    private void Job_JobPaused(object sender, EventArgs e) {
     220      pauseStopSem.Release();
    191221    }
    192222
Note: See TracChangeset for help on using the changeset viewer.