Пример #1
0
        public async Task CreateJobAsync(CreateJobOptions createJobOptions)
        {
            CloudJob unboundJob = this.Client.JobOperations.CreateJob();

            unboundJob.Id = createJobOptions.JobId;
            unboundJob.Priority = createJobOptions.Priority;
            unboundJob.Constraints = new JobConstraints(createJobOptions.MaxWallClockTime, createJobOptions.MaxRetryCount);

            PoolInformation poolInformation = new PoolInformation();
            if (createJobOptions.AutoPoolOptions.UseAutoPool.HasValue && createJobOptions.AutoPoolOptions.UseAutoPool.Value)
            {
                AutoPoolSpecification autoPoolSpecification = new AutoPoolSpecification()
                {
                    AutoPoolIdPrefix = createJobOptions.AutoPoolOptions.AutoPoolPrefix,
                    KeepAlive = createJobOptions.AutoPoolOptions.KeepAlive,
                    PoolLifetimeOption = (PoolLifetimeOption)Enum.Parse(typeof(PoolLifetimeOption), createJobOptions.AutoPoolOptions.LifeTimeOption),
                    PoolSpecification = new PoolSpecification()
                    {
                        OSFamily = createJobOptions.AutoPoolOptions.OSFamily,
                        VirtualMachineSize = createJobOptions.AutoPoolOptions.VirutalMachineSize,
                        TargetDedicated = createJobOptions.AutoPoolOptions.TargetDedicated
                    }
                };

                poolInformation.AutoPoolSpecification = autoPoolSpecification;
            }
            else
            {
                poolInformation.PoolId = createJobOptions.PoolId;
            }

            unboundJob.PoolInformation = poolInformation;

            if (createJobOptions.CreateJobManager.HasValue && createJobOptions.CreateJobManager.Value == true)
            {
                JobManagerTask jobManager = new JobManagerTask()
                {
                    CommandLine = createJobOptions.JobManagerOptions.CommandLine,
                    KillJobOnCompletion = createJobOptions.JobManagerOptions.KillOnCompletion,
                    Id = createJobOptions.JobManagerOptions.JobManagerId
                };

                jobManager.Constraints = new TaskConstraints(
                    createJobOptions.JobManagerOptions.MaxTaskWallClockTime, 
                    createJobOptions.JobManagerOptions.RetentionTime, 
                    createJobOptions.JobManagerOptions.MaxTaskRetryCount);

                unboundJob.JobManagerTask = jobManager;
            }

            await unboundJob.CommitAsync();
        }
 public Task CreateJobAsync(CreateJobOptions options)
 {
     return this.Service.CreateJobAsync(options);
 }
        private async Task CreateJobScheduleAsync()
        {
            try
            {
                if (this.IsInputValid())
                {
                    string osFamilyString;
                    if (Common.SupportedOSFamilyDictionary.ContainsKey(this.SelectedOSFamily))
                    {
                        osFamilyString = Common.SupportedOSFamilyDictionary[this.SelectedOSFamily];
                    }
                    else
                    {
                        osFamilyString = this.SelectedOSFamily;
                    }

                    CreateJobOptions options = new CreateJobOptions()
                    {
                        CreateJobManager = this.IsCreateJobManagerSelected,
                        MaxRetryCount = Common.GetNullableIntValue(this.MaxRetryCount),
                        MaxWallClockTime = this.MaxWallClockTime,
                        Priority = Common.GetNullableIntValue(this.Priority),
                        JobId = this.JobId,
                        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.CreateJobAsync(options);

                    Messenger.Default.Send<RefreshMessage>(new RefreshMessage(RefreshTarget.Jobs));

                    Messenger.Default.Send(new GenericDialogMessage(string.Format("Successfully created job {0}", this.JobId)));
                    this.JobId = 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()));
            }
        }