/// <summary>
        /// Waits for a job to be created -- This should be removed when we have a Utilities helper which does this
        /// </summary>
        public static CloudJobSchedule WaitForJobOnJobSchedule(JobScheduleOperations jobScheduleOperations, string jobScheduleId, string expectedJobId = null, TimeSpan?timeout = null)
        {
            //Wait for the job
            TimeSpan         jobCreationTimeout       = timeout ?? TimeSpan.FromSeconds(30);
            CloudJobSchedule refreshableJobSchedule   = jobScheduleOperations.GetJobSchedule(jobScheduleId);
            DateTime         jobCreationWaitStartTime = DateTime.UtcNow;

            while (refreshableJobSchedule.ExecutionInformation == null ||
                   refreshableJobSchedule.ExecutionInformation.RecentJob == null ||
                   (!string.IsNullOrEmpty(expectedJobId) && refreshableJobSchedule.ExecutionInformation.RecentJob.Id != expectedJobId))
            {
                Thread.Sleep(TimeSpan.FromSeconds(10));
                refreshableJobSchedule.Refresh();
                if (DateTime.UtcNow > jobCreationWaitStartTime.Add(jobCreationTimeout))
                {
                    throw new Exception("Timed out waiting for job");
                }
            }

            return(refreshableJobSchedule);
        }
Exemple #2
0
        /// <summary>
        /// Lists the job schedules matching the specified filter options.
        /// </summary>
        /// <param name="options">The options to use when querying for job schedules.</param>
        /// <returns>The workitems matching the specified filter options.</returns>
        public IEnumerable <PSCloudJobSchedule> ListJobSchedules(ListJobScheduleOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Get the single job schedule matching the specified id
            if (!string.IsNullOrWhiteSpace(options.JobScheduleId))
            {
                WriteVerbose(string.Format(Resources.GetJobScheduleById, options.JobScheduleId));
                JobScheduleOperations jobScheduleOperations = options.Context.BatchOMClient.JobScheduleOperations;
                ODATADetailLevel      getDetailLevel        = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
                CloudJobSchedule      jobSchedule           = jobScheduleOperations.GetJobSchedule(options.JobScheduleId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
                PSCloudJobSchedule    psJobSchedule         = new PSCloudJobSchedule(jobSchedule);
                return(new PSCloudJobSchedule[] { psJobSchedule });
            }
            // List job schedules using the specified filter
            else
            {
                string           verboseLogString = null;
                ODATADetailLevel listDetailLevel  = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString             = Resources.GetJobScheduleByOData;
                    listDetailLevel.FilterClause = options.Filter;
                }
                else
                {
                    verboseLogString = Resources.GetJobScheduleNoFilter;
                }
                WriteVerbose(verboseLogString);

                JobScheduleOperations jobScheduleOperations                 = options.Context.BatchOMClient.JobScheduleOperations;
                IPagedEnumerable <CloudJobSchedule>         workItems       = jobScheduleOperations.ListJobSchedules(listDetailLevel, options.AdditionalBehaviors);
                Func <CloudJobSchedule, PSCloudJobSchedule> mappingFunction = j => { return(new PSCloudJobSchedule(j)); };
                return(PSPagedEnumerable <PSCloudJobSchedule, CloudJobSchedule> .CreateWithMaxCount(
                           workItems, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
            }
        }