/// <summary> /// Event triggered when job monitor entry's instance is exited /// </summary> /// <param name="sender">indicating the sender</param> /// <param name="e">indicating the event args</param> private void JobMonitorEntry_Exit(object sender, EventArgs e) { AzureBatchJobMonitorEntry entry = (AzureBatchJobMonitorEntry)sender; Debug.Assert(entry != null, "[AzureBatchSchedulerDelegation] Sender should be an instance of JobMonitorEntry class."); lock (this.JobMonitors) { this.JobMonitors.Remove(entry.SessionId); } entry.Exit -= new EventHandler(this.JobMonitorEntry_Exit); entry.Close(); Trace.TraceInformation($"[AzureBatchSchedulerDelegation] End: JobMonitorEntry Exit."); }
/// <summary> /// Start to subscribe the job and task event /// </summary> /// <param name="jobid">indicating the job id</param> /// <param name="autoMax">indicating the auto max property of the job</param> /// <param name="autoMin">indicating the auto min property of the job</param> public async Task <(JobState jobState, int autoMax, int autoMin)> RegisterJobAsync(string jobid) { Trace.TraceInformation($"[AzureBatchSchedulerDelegation] Begin: RegisterJob, job id is {jobid}..."); //CheckBrokerAccess(jobid); int autoMax = 0, autoMin = 0; CloudJob batchJob; try { AzureBatchJobMonitorEntry jobMonitorEntry; lock (this.JobMonitors) { if (!this.JobMonitors.TryGetValue(jobid, out jobMonitorEntry)) { jobMonitorEntry = new AzureBatchJobMonitorEntry(jobid); jobMonitorEntry.Exit += new EventHandler(this.JobMonitorEntry_Exit); } } batchJob = await jobMonitorEntry.StartAsync(System.ServiceModel.OperationContext.Current); // Bug 18050: Only add/update the instance if it succeeded to // open the job. lock (this.JobMonitors) { this.JobMonitors[jobid] = jobMonitorEntry; } autoMin = jobMonitorEntry.MinUnits; autoMax = jobMonitorEntry.MaxUnits; } catch (Exception e) { Trace.TraceError($"[AzureBatchSchedulerDelegation] Exception thrown while registering job: {jobid}", e); throw; } Trace.TraceInformation($"[AzureBatchSchedulerDelegation] End: RegisterJob. Current job state = {batchJob.State}."); return(await AzureBatchJobStateConverter.FromAzureBatchJobAsync(batchJob), autoMax, autoMin); }