Exemplo n.º 1
0
 /// <summary>
 /// Releases the specified job lock.
 /// </summary>
 /// <param name="jobLock">The job lock.</param>
 public override void Release(JobLock jobLock)
 {
     lock (_myLock)
     {
         if (jobLock.LockAcquired)
         {
             _locks.Remove(jobLock.LockName);
         }
         jobLock.SetReleased();
     }
 }
Exemplo n.º 2
0
 private void RunInternal()
 {
     if (!this.IsBusy)
     {
         this.IsBusy = true;
         using (JobLock @lock = this._jobLockProvider.Acquire(this.Name))
         {
             if ([email protected])
             {
                 this.LastResult = "Could not acquire a job lock.";
                 this.LastStatus = JobStatus.Canceled;
                 this.Status     = JobStatus.Waiting;
                 this.IsBusy     = false;
             }
             else
             {
                 DateTime now = DateTime.Now;
                 this.LastRunStartTime = now;
                 JobManager.Current.OnJobRunning(new JobEventArgs(this.Name, JobAction.Running, this._id));
                 Trace.TraceInformation("Run job '{0}' at {1}.", new object[] { this.Name, now });
                 this.Status = JobStatus.Running;
                 Interlocked.Increment(ref JobManager.JobsRunning);
                 try
                 {
                     this.CreateInstance();
                     JobContext context = new JobContext(this.Name, this.Description, this.LastRunStartTime, this.LastStatus, this.Arguments, new Action <string>(this.UpdateStatus));
                     JobResult  result  = this._instance.Run(context);
                     if (result == null)
                     {
                         if (string.IsNullOrEmpty(this.LastResult))
                         {
                             this.LastResult = "Completed";
                         }
                         this.LastStatus = JobStatus.Completed;
                     }
                     else if (result.Error != null)
                     {
                         this.LastResult = result.Error.Message;
                         this.LastStatus = JobStatus.Error;
                         Trace.TraceError(result.Error.ToString());
                     }
                     else
                     {
                         if (result.Result != null)
                         {
                             this.LastResult = result.Result.ToString();
                         }
                         this.LastStatus = JobStatus.Completed;
                     }
                 }
                 catch (Exception exception)
                 {
                     this.LastResult = exception.Message;
                     this.LastStatus = JobStatus.Error;
                     Trace.TraceError(exception.ToString());
                 }
                 finally
                 {
                     Interlocked.Decrement(ref JobManager.JobsRunning);
                     this.LastRunFinishTime = DateTime.Now;
                     if (!this._keepAlive)
                     {
                         this._instance = null;
                     }
                     try
                     {
                         if (this._jobHistoryProvider != null)
                         {
                             this._jobHistoryProvider.SaveHistory(this);
                         }
                     }
                     catch (Exception exception2)
                     {
                         Trace.TraceError("Error saving job history: " + exception2.Message);
                     }
                     JobManager.Current.OnJobCompleted(new JobCompletedEventArgs(this.Name, JobAction.Completed, this._id, now, this.LastRunFinishTime, this.LastResult, this.LastStatus));
                     Trace.TraceInformation("Job '{0}' completed with status '{1}'.", new object[] { this.Name, this.LastStatus });
                     this.Status = JobStatus.Waiting;
                     this.IsBusy = false;
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Releases the specified job lock.
 /// </summary>
 /// <param name="jobLock">The job lock.</param>
 public abstract void Release(JobLock jobLock);