public static async Task CreateBatchJob()

in SQL-Hybrid-Cloud-Toolkit/Components/ADP/ADPControl/BatchActivity.cs [66:100]


        public static async Task<CloudJob> CreateBatchJob(BatchClient batchClient, string jobId, ILogger log)
        {
            // Create a Batch job
            log.LogInformation("Creating job [{0}]...", jobId);
            CloudJob job = null;

            try
            {
                job = batchClient.JobOperations.CreateJob(jobId, new PoolInformation { PoolId = PoolId });
                job.OnAllTasksComplete = OnAllTasksComplete.TerminateJob;

                // Commit the job to the Batch service
                await job.CommitAsync();

                log.LogInformation($"Created job {jobId}");

                // Obtain the bound job from the Batch service
                await job.RefreshAsync();
            }
            catch (BatchException be)
            {
                // Accept the specific error code JobExists as that is expected if the job already exists
                if (be.RequestInformation?.BatchError?.Code == BatchErrorCodeStrings.JobExists)
                {
                    log.LogWarning("The job {0} already existed when we tried to create it", jobId);
                }
                else
                {
                    log.LogError("Exception creating job: {0}", be.Message);
                    throw be; // Any other exception is unexpected
                }
            }

            return job;
        }