Microsoft.Azure.Commands.Batch.Models.BatchClient.ListJobs C# (CSharp) Method

ListJobs() public method

Lists the jobs matching the specified filter options.
public ListJobs ( ListJobOptions options ) : IEnumerable
options ListJobOptions The options to use when querying for jobs.
return IEnumerable
        public IEnumerable<PSCloudJob> ListJobs(ListJobOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Get the single job matching the specified id
            if (!string.IsNullOrEmpty(options.JobId))
            {
                WriteVerbose(string.Format(Resources.GetJobById, options.JobId));
                JobOperations jobOperations = options.Context.BatchOMClient.JobOperations;
                ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
                CloudJob job = jobOperations.GetJob(options.JobId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
                PSCloudJob psJob = new PSCloudJob(job);
                return new PSCloudJob[] { psJob };
            }
            // List jobs using the specified filter
            else
            {
                string jobScheduleId = options.JobSchedule == null ? options.JobScheduleId : options.JobSchedule.Id;
                bool filterByJobSchedule = !string.IsNullOrEmpty(jobScheduleId);
                ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);

                string verboseLogString = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString = filterByJobSchedule ? Resources.GetJobByOData : string.Format(Resources.GetJobByODataAndJobSChedule, jobScheduleId);
                    listDetailLevel.FilterClause = options.Filter;
                }
                else
                {
                    verboseLogString = filterByJobSchedule ? Resources.GetJobNoFilter : string.Format(Resources.GetJobByJobScheduleNoFilter, jobScheduleId);
                }
                WriteVerbose(verboseLogString);

                IPagedEnumerable<CloudJob> jobs = null;
                if (filterByJobSchedule)
                {
                    JobScheduleOperations jobScheduleOperations = options.Context.BatchOMClient.JobScheduleOperations;
                    jobs = jobScheduleOperations.ListJobs(jobScheduleId, listDetailLevel, options.AdditionalBehaviors);
                }
                else
                {
                    JobOperations jobOperations = options.Context.BatchOMClient.JobOperations;
                    jobs = jobOperations.ListJobs(listDetailLevel, options.AdditionalBehaviors);
                }
                Func<CloudJob, PSCloudJob> mappingFunction = j => { return new PSCloudJob(j); };
                return PSPagedEnumerable<PSCloudJob, CloudJob>.CreateWithMaxCount(
                    jobs, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)));
            }
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Waits for the job to complete
        /// </summary>
        public static PSCloudJob WaitForJobCompletion(BatchController controller, BatchAccountContext context, string jobId, string taskId)
        {
            BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient);

            PSCloudJob job = client.ListJobs(new ListJobOptions(context)).First(cloudJob => cloudJob.Id == jobId);

            DateTime timeout = DateTime.Now.AddMinutes(10);

            while (job.State != JobState.Completed || DateTime.Now > timeout)
            {
                job = client.ListJobs(new ListJobOptions(context)).First(cloudJob => cloudJob.Id == jobId);

                TestMockSupport.Delay(20000);
            }

            return(job);
        }
All Usage Examples Of Microsoft.Azure.Commands.Batch.Models.BatchClient::ListJobs
BatchClient