예제 #1
0
 void ValidateCompletedCmdlet <T>(AzureLongRunningJob <T> job) where T : AzurePSCmdlet
 {
     Assert.Equal("Completed", job.StatusMessage);
     Assert.True(job.HasMoreData);
     Assert.Contains(job.Debug, t => t.Message == Debug);
     Assert.Collection(job.Warning, t => Assert.Equal(Warning, t.Message));
     Assert.Collection(job.Verbose, t => Assert.Equal(Verbose, t.Message));
     Assert.Collection(job.Progress, t => Assert.Equal(Progress, t));
     Assert.Collection(job.Output, t => Assert.Equal(Output, t.BaseObject));
     Assert.Collection(job.Error, t => Assert.Equal(Error, t));
 }
예제 #2
0
        /// <summary>
        /// Execute this cmdlet in the background and return a job that tracks the results
        /// </summary>
        /// <typeparam name="T">The cmdlet type</typeparam>
        /// <param name="cmdlet">The cmdlet to execute</param>
        /// <param name="jobName">The name of the job</param>
        /// <param name="executor">The method to execute in the background job</param>
        /// <returns>The job tracking cmdlet execution</returns>
        public static Job ExecuteAsJob <T>(this T cmdlet, string jobName, Action <T> executor) where T : AzurePSCmdlet
        {
            if (cmdlet == null)
            {
                throw new ArgumentNullException(nameof(cmdlet));
            }

            if (executor == null)
            {
                throw new ArgumentNullException(nameof(executor));
            }

            var job = AzureLongRunningJob <T> .Create(cmdlet, cmdlet?.MyInvocation?.MyCommand?.Name, jobName, executor);

            cmdlet.SafeAddToJobRepository(job);
            ThreadPool.QueueUserWorkItem(job.RunJob, job);
            return(job);
        }
예제 #3
0
 void WaitForCompletion(AzureLongRunningJob job, Action <AzureLongRunningJob> validate)
 {
     job.StateChanged += this.HandleStateChange;
     try
     {
         HandleStateChange(job, new JobStateEventArgs(job.JobStateInfo, new JobStateInfo(JobState.NotStarted)));
         jobCompleted.WaitOne(TimeSpan.FromHours(4));
         validate(job);
     }
     finally
     {
         job.StateChanged -= this.HandleStateChange;
         foreach (var message in job.Debug)
         {
             xunitLogger.Information(message?.Message);
         }
     }
 }
예제 #4
0
 void WaitForCompletion(AzureLongRunningJob job, Action <AzureLongRunningJob> validate)
 {
     job.StateChanged += this.HandleStateChange;
     try
     {
         if (this.jobCompleted.WaitOne(TimeSpan.FromSeconds(10)))
         {
             validate(job);
         }
         else
         {
             throw new InvalidOperationException("Job did not complete");
         }
     }
     finally
     {
         job.StateChanged -= this.HandleStateChange;
     }
 }