Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/23/09 11:35:41 (15 years ago)
Author:
svonolfe
Message:

Avoid out of memory exceptions related to job objects (#372)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/JobManager.cs

    r2005 r2082  
    7373    public void ResetJobsDependingOnResults(Job job) {
    7474      ISession session = factory.GetSessionForCurrentThread();
     75      ITransaction tx = null;
    7576
    7677      try {
     
    7879            session.GetDataAdapter<Job, IJobAdapter>();
    7980
    80         JobResult lastJobResult = GetLastJobResult(job);
    81         if (lastJobResult != null) {
    82           job.Percentage = lastJobResult.Percentage;
    83           job.SerializedJob = lastJobResult.Result;
    84         } else {
    85           job.Percentage = 0;
    86         }
    87 
    88         job.Client = null;
    89         job.State = State.offline;
    90 
    91         jobAdapter.Update(job);
     81        tx = session.BeginTransaction();
     82
     83        if (job != null) {
     84          ComputableJob computableJob =
     85              new ComputableJob();
     86          computableJob.JobInfo =
     87            job;
     88
     89          JobResult lastJobResult = GetLastJobResult(job);
     90          if (lastJobResult != null) {
     91            computableJob.JobInfo.Percentage = lastJobResult.Percentage;
     92            computableJob.SerializedJob = lastJobResult.Result;
     93
     94            jobAdapter.UpdateComputableJob(computableJob);
     95          } else {
     96            computableJob.JobInfo.Percentage = 0;
     97          }
     98
     99          computableJob.JobInfo.Client = null;
     100          computableJob.JobInfo.State = State.offline;
     101
     102          jobAdapter.Update(computableJob.JobInfo);
     103        }
     104
     105        tx.Commit();
     106      }
     107      catch (Exception ex) {
     108        if (tx != null)
     109          tx.Rollback();
     110        throw ex;
    92111      }
    93112      finally {
     
    185204    /// <param name="job"></param>
    186205    /// <returns></returns>
    187     public ResponseObject<Job> AddNewJob(Job job) {
     206    public ResponseObject<Job> AddNewJob(ComputableJob job) {
    188207      ISession session = factory.GetSessionForCurrentThread();
    189208
     
    194213        ResponseObject<Job> response = new ResponseObject<Job>();
    195214
    196         if (job != null) {
    197           if (job.State != State.offline) {
     215        if (job != null && job.JobInfo != null) {
     216          if (job.JobInfo.State != State.offline) {
    198217            response.Success = false;
    199218            response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOBSTATE_MUST_BE_OFFLINE;
    200219            return response;
    201220          }
    202           if (job.Id != Guid.Empty) {
     221          if (job.JobInfo.Id != Guid.Empty) {
    203222            response.Success = false;
    204223            response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ID_MUST_NOT_BE_SET;
     
    211230          }
    212231
    213           job.DateCreated = DateTime.Now;
    214           jobAdapter.Update(job);
     232          job.JobInfo.DateCreated = DateTime.Now;
     233          jobAdapter.UpdateComputableJob(job);
    215234          response.Success = true;
    216           response.Obj = job;
     235          response.Obj = job.JobInfo;
    217236          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_ADDED;
    218237        } else {
Note: See TracChangeset for help on using the changeset viewer.