/// <summary> /// Creates a job schedule with the specified options. /// </summary> /// <param name="options">The options describing the job schedule to create.</param> /// <returns></returns> public async Task CreateJobScheduleAsync(CreateJobScheduleOptions options) { CloudJobSchedule unboundJobSchedule = this.Client.JobScheduleOperations.CreateJobSchedule(); unboundJobSchedule.Id = options.JobScheduleId; PoolInformation poolInformation = new PoolInformation(); if (options.AutoPoolOptions.UseAutoPool.HasValue && options.AutoPoolOptions.UseAutoPool.Value) { AutoPoolSpecification autoPoolSpecification = new AutoPoolSpecification() { AutoPoolIdPrefix = options.AutoPoolOptions.AutoPoolPrefix, KeepAlive = options.AutoPoolOptions.KeepAlive, PoolLifetimeOption = (PoolLifetimeOption)Enum.Parse(typeof(PoolLifetimeOption), options.AutoPoolOptions.LifeTimeOption), PoolSpecification = new PoolSpecification() { OSFamily = options.AutoPoolOptions.OSFamily, VirtualMachineSize = options.AutoPoolOptions.VirutalMachineSize, TargetDedicated = options.AutoPoolOptions.TargetDedicated } }; poolInformation.AutoPoolSpecification = autoPoolSpecification; } else { poolInformation.PoolId = options.PoolId; } unboundJobSchedule.JobSpecification = new JobSpecification() { Priority = options.Priority, PoolInformation = poolInformation }; // TODO: These are read only unboundJobSchedule.JobSpecification.Constraints = new JobConstraints(options.MaxWallClockTime, options.MaxRetryCount); Schedule schedule = new Schedule() { DoNotRunAfter = options.DoNotRunAfter, DoNotRunUntil = options.DoNotRunUntil, RecurrenceInterval = options.RecurrenceInterval, StartWindow = options.StartWindow }; unboundJobSchedule.Schedule = schedule; if (options.CreateJobManager.HasValue && options.CreateJobManager.Value == true) { JobManagerTask jobManager = new JobManagerTask() { CommandLine = options.JobManagerOptions.CommandLine, KillJobOnCompletion = options.JobManagerOptions.KillOnCompletion, Id = options.JobManagerOptions.JobManagerId }; jobManager.Constraints = new TaskConstraints(options.JobManagerOptions.MaxTaskWallClockTime, options.JobManagerOptions.RetentionTime, options.JobManagerOptions.MaxTaskRetryCount); unboundJobSchedule.JobSpecification.JobManagerTask = jobManager; } await unboundJobSchedule.CommitAsync(); }
public async Task CreateJobScheduleAsync(CreateJobScheduleOptions options) { await this.Service.CreateJobScheduleAsync(options); }
private async Task CreateJobScheduleAsync() { try { if (this.IsInputValid()) { string osFamilyString = null; if (this.UseAutoPool) { if (Common.SupportedOSFamilyDictionary.ContainsKey(this.SelectedOSFamily)) { osFamilyString = Common.SupportedOSFamilyDictionary[this.SelectedOSFamily]; } else { osFamilyString = this.SelectedOSFamily; } } CreateJobScheduleOptions options = new CreateJobScheduleOptions() { DoNotRunAfter = this.DoNotRunAfter, DoNotRunUntil = this.DoNotRunUntil, CreateJobManager = this.IsCreateJobManagerSelected, MaxRetryCount = Common.GetNullableIntValue(this.MaxRetryCount), MaxWallClockTime = this.MaxWallClockTime, Priority = Common.GetNullableIntValue(this.Priority), RecurrenceInterval = this.RecurrenceInterval, StartWindow = this.StartWindow, JobScheduleId = this.JobScheduleId, PoolId = this.PoolId, AutoPoolOptions = new CreateAutoPoolOptions() { AutoPoolPrefix = this.AutoPoolPrefix, LifeTimeOption = this.SelectedLifetimeOption, KeepAlive = this.SelectedKeepAliveItem, OSFamily = osFamilyString, SelectedLifetimeOption = this.SelectedLifetimeOption, TargetDedicated = this.TargetDedicated, UseAutoPool = this.UseAutoPool, VirutalMachineSize = this.SelectedVirtualMachineSize }, JobManagerOptions = new CreateJobManagerOptions() { CommandLine = this.CommandLine, JobManagerId = this.JobManagerId, KillOnCompletion = this.KillOnCompletionSelectedItem, MaxTaskRetryCount = Common.GetNullableIntValue(this.MaxRetryCount), MaxTaskWallClockTime = this.MaxTaskWallClockTime, RetentionTime = this.RetentionTime } }; await this.batchService.CreateJobScheduleAsync(options); Messenger.Default.Send<RefreshMessage>(new RefreshMessage(RefreshTarget.JobSchedules)); Messenger.Default.Send(new GenericDialogMessage(string.Format("Successfully created job schedule {0}", this.JobScheduleId))); this.JobScheduleId = string.Empty; //So that the user cannot accidentally try to create the same job schedule twice } } catch (Exception e) { Messenger.Default.Send<GenericDialogMessage>(new GenericDialogMessage(e.ToString())); } }