// Token: 0x060005A6 RID: 1446 RVA: 0x00022104 File Offset: 0x00020304
        public OneTimeJobRawResult ExecuteJob(JobDescription jobDescription, CredentialBase jobCredential = null)
        {
            if (this.listenerUri == string.Empty)
            {
                JobSchedulerEventServicev2.log.Error("ListenerUri remains uninitialized");
                OneTimeJobRawResult result = new OneTimeJobRawResult
                {
                    Success = false,
                    Error   = Resources.TestErrorJobFailed
                };
                return(result);
            }
            if (jobCredential != null)
            {
                jobDescription.Credential = this.EncryptCredentials(jobCredential);
            }
            if (jobDescription.SupportedRoles == null)
            {
                jobDescription.SupportedRoles = 7;
            }
            ScheduledJob job = new ScheduledJob
            {
                NotificationAddress = this.listenerUri,
                State     = "CoreOneTimeJob",
                RunOnce   = true,
                IsOneShot = true,
                Job       = jobDescription
            };
            Guid guid;

            try
            {
                guid = this.SubmitScheduledJobToScheduler(job);
                OneTimeJobManager.Logger.DebugFormat("Job {0} scheduled", guid);
            }
            catch (Exception ex)
            {
                OneTimeJobManager.Logger.ErrorFormat("Failed to submit job: {0}", ex);
                OneTimeJobRawResult result = default(OneTimeJobRawResult);
                result.Success          = false;
                result.Error            = Resources.TestErrorJobFailed;
                result.ExceptionFromJob = ex;
                return(result);
            }
            TimeSpan timeSpan = jobDescription.Timeout.Add(this.jobTimeoutTolerance);

            OneTimeJobManager.PendingJobItem pendingJobItem = new OneTimeJobManager.PendingJobItem();
            this.pendingJobs[guid] = pendingJobItem;
            if (this.JobStarted != null)
            {
                this.JobStarted(this, new OneTimeJobManager.JobStartedEventArgs(guid));
            }
            OneTimeJobRawResult result2;

            if (pendingJobItem.WaitHandle.WaitOne(timeSpan))
            {
                result2 = pendingJobItem.RawResult;
            }
            else
            {
                OneTimeJobManager.Logger.ErrorFormat("No result from job {0} received before timeout ({1})", guid, timeSpan);
                result2 = new OneTimeJobRawResult
                {
                    Success = false,
                    Error   = Resources.TestErrorTimeout
                };
            }
            this.pendingJobs.TryRemove(guid, out pendingJobItem);
            return(result2);
        }
Exemple #2
0
        public OneTimeJobRawResult ExecuteJob(
            JobDescription jobDescription,
            CredentialBase jobCredential = null)
        {
            if (this.listenerUri == string.Empty)
            {
                JobSchedulerEventServicev2.log.Error((object)"ListenerUri remains uninitialized");
                return(new OneTimeJobRawResult()
                {
                    Success = false,
                    Error = Resources.get_TestErrorJobFailed()
                });
            }
            if (jobCredential != null)
            {
                jobDescription.set_Credential(this.EncryptCredentials(jobCredential));
            }
            if (jobDescription.get_SupportedRoles() == null)
            {
                jobDescription.set_SupportedRoles((PackageType)7);
            }
            ScheduledJob scheduledJob = new ScheduledJob();

            scheduledJob.set_NotificationAddress(this.listenerUri);
            scheduledJob.set_State("CoreOneTimeJob");
            scheduledJob.set_RunOnce(true);
            scheduledJob.set_IsOneShot(true);
            scheduledJob.set_Job(jobDescription);
            ScheduledJob job = scheduledJob;
            Guid         scheduler;

            try
            {
                scheduler = this.SubmitScheduledJobToScheduler(job);
                OneTimeJobManager.Logger.DebugFormat("Job {0} scheduled", (object)scheduler);
            }
            catch (Exception ex)
            {
                OneTimeJobManager.Logger.ErrorFormat("Failed to submit job: {0}", (object)ex);
                OneTimeJobRawResult timeJobRawResult = new OneTimeJobRawResult();
                timeJobRawResult.Success          = false;
                timeJobRawResult.Error            = Resources.get_TestErrorJobFailed();
                timeJobRawResult.ExceptionFromJob = ex;
                timeJobRawResult = timeJobRawResult;
                return(timeJobRawResult);
            }
            TimeSpan timeout = jobDescription.get_Timeout().Add(this.jobTimeoutTolerance);

            OneTimeJobManager.PendingJobItem pendingJobItem = new OneTimeJobManager.PendingJobItem();
            this.pendingJobs[scheduler] = pendingJobItem;
            if (this.JobStarted != null)
            {
                this.JobStarted((object)this, (EventArgs) new OneTimeJobManager.JobStartedEventArgs(scheduler));
            }
            OneTimeJobRawResult timeJobRawResult1;

            if (pendingJobItem.WaitHandle.WaitOne(timeout))
            {
                timeJobRawResult1 = pendingJobItem.RawResult;
            }
            else
            {
                OneTimeJobManager.Logger.ErrorFormat("No result from job {0} received before timeout ({1})", (object)scheduler, (object)timeout);
                timeJobRawResult1 = new OneTimeJobRawResult()
                {
                    Success = false,
                    Error   = Resources.get_TestErrorTimeout()
                };
            }
            this.pendingJobs.TryRemove(scheduler, out pendingJobItem);
            return(timeJobRawResult1);
        }