Example #1
0
        /// <summary>
        /// Commits this <see cref="CloudJob" /> to the Azure Batch service.
        /// </summary>
        /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
        /// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <remarks>
        /// <para>If the <see cref="CloudJob"/> already exists on the Batch service, its properties are replaced by the properties of this <see cref="CloudJob"/>.</para>
        /// <para>The commit operation runs asynchronously.</para>
        /// </remarks>
        public async Task CommitAsync(
            IEnumerable <BatchClientBehavior> additionalBehaviors = null,
            CancellationToken cancellationToken = default)
        {
            // first forbid actions during commit
            this.propertyContainer.IsReadOnly = true;

            // craft the behavior manager for this call
            BehaviorManager behaveMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors);

            // hold the tpl task for the server call
            Task asyncTask;

            if (BindingState.Unbound == this.propertyContainer.BindingState) // unbound commit
            {
                // take all property changes and create a job
                Models.JobAddParameter protoJob = this.GetTransportObject();

                asyncTask = parentBatchClient.ProtocolLayer.AddJob(protoJob, behaveMgr, cancellationToken);
            }
            else
            {
                Models.MetadataItem[]  modelMetadata        = UtilitiesInternal.ConvertToProtocolArray(this.Metadata);
                Models.JobConstraints  modelJobConstraints  = UtilitiesInternal.CreateObjectWithNullCheck(this.Constraints, item => item.GetTransportObject());
                Models.PoolInformation modelPoolInformation = UtilitiesInternal.CreateObjectWithNullCheck(this.PoolInformation, item => item.GetTransportObject());

                asyncTask = this.parentBatchClient.ProtocolLayer.UpdateJob(
                    Id,
                    Priority,
                    UtilitiesInternal.MapNullableEnum <Common.OnAllTasksComplete, Models.OnAllTasksComplete>(this.OnAllTasksComplete),
                    modelPoolInformation,
                    modelJobConstraints,
                    MaxParallelTasks,
                    AllowTaskPreemption,
                    modelMetadata,
                    behaveMgr,
                    cancellationToken);
            }

            await asyncTask.ConfigureAwait(continueOnCapturedContext : false);
        }
Example #2
0
        /// <summary>
        /// Commits this <see cref="CloudJobSchedule" /> to the Azure Batch service.
        /// </summary>
        /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns>
        /// <remarks>
        /// <para>The commit operation runs asynchronously.</para>
        /// </remarks>
        public async System.Threading.Tasks.Task CommitAsync(
            IEnumerable <BatchClientBehavior> additionalBehaviors = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            // after this no prop access is allowed
            this.propertyContainer.IsReadOnly = true;

            // craft the behavior manager for this call
            BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors);

            // fetch props with admin rights so we can make calls, etc.

            if (BindingState.Unbound == this.propertyContainer.BindingState)
            {
                // take all property changes and create a job schedule
                Models.JobScheduleAddParameter protoJobSchedule = this.GetTransportObject <Models.JobScheduleAddParameter>();

                System.Threading.Tasks.Task <AzureOperationHeaderResponse <Models.JobScheduleAddHeaders> > asyncTask =
                    this.parentBatchClient.ProtocolLayer.AddJobSchedule(protoJobSchedule, bhMgr, cancellationToken);

                await asyncTask.ConfigureAwait(continueOnCapturedContext : false);
            }
            else
            {
                Models.JobSpecification jobSpecification = UtilitiesInternal.CreateObjectWithNullCheck(this.JobSpecification, o => o.GetTransportObject());
                Models.Schedule         schedule         = UtilitiesInternal.CreateObjectWithNullCheck(this.Schedule, o => o.GetTransportObject());
                Models.MetadataItem[]   metadata         = UtilitiesInternal.ConvertToProtocolArray(this.Metadata);

                System.Threading.Tasks.Task <AzureOperationHeaderResponse <Models.JobScheduleUpdateHeaders> > asyncJobScheduleUpdate =
                    this.parentBatchClient.ProtocolLayer.UpdateJobSchedule(
                        this.Id,
                        jobSpecification,
                        metadata,
                        schedule,
                        bhMgr,
                        cancellationToken);

                await asyncJobScheduleUpdate.ConfigureAwait(continueOnCapturedContext : false);
            }
        }