public async static Task <Telepathy.Session.Data.JobState> FromAzureBatchJobAsync(CloudJob job) { //Handle job state Active independantly in case of batch tasks are not running using (var batchClient = AzureBatchConfiguration.GetBatchClient()) { if (job.State == JobState.Active) { ODATADetailLevel detail = new ODATADetailLevel(selectClause: "id,state"); List <CloudTask> allTasks = await batchClient.JobOperations.ListTasks(job.Id, detail).ToListAsync(); if (allTasks.Exists(task => task.State == TaskState.Running)) { return(Telepathy.Session.Data.JobState.Running); } return(Telepathy.Session.Data.JobState.Queued); } else if (job.State == JobState.Terminating) { ODATADetailLevel detail = new ODATADetailLevel(selectClause: "id,state"); List <CloudTask> allTasks = await batchClient.JobOperations.ListTasks(job.Id, detail).ToListAsync(); if (allTasks.Exists(task => task.State != TaskState.Completed)) { return(Telepathy.Session.Data.JobState.Canceling); } return(Telepathy.Session.Data.JobState.Finishing); } } return(JobStateMapping[(JobState)job.State]); }
/// <summary> /// Initializes a new instance of the JobMonitorEntry class /// </summary> /// <param name="sessionid">indicating the session id</param> public AzureBatchJobMonitor(string sessionid, Action <Telepathy.Session.Data.JobState, List <TaskInfo>, bool> reportJobStateAction) { this.sessionid = sessionid; this.batchClient = AzureBatchConfiguration.GetBatchClient(); this.ReportJobStateAction = reportJobStateAction; this.lastChangeTime = SqlDateTime.MinValue.Value; this.skus = loadSKUs(); }
public async Task <bool> UpdateBrokerInfoAsync(string sessionId, Dictionary <string, object> properties) { try { using (var batchClient = AzureBatchConfiguration.GetBatchClient()) { TraceHelper.TraceEvent(sessionId, TraceEventType.Information, "[AzureBatchSchedulerDelegation] UpdateBrokerInfo..."); StringBuilder sb = new System.Text.StringBuilder(); foreach (KeyValuePair <string, object> property in properties) { sb.AppendLine($"Property = {property.Key}\tValue = {property.Value}"); } TraceHelper.TraceEvent(sessionId, TraceEventType.Verbose, "[AzureBatchSchedulerDelegation] Properties detail:\n{0}", sb.ToString()); var sessionJob = await batchClient.JobOperations.GetJobAsync(AzureBatchSessionJobIdConverter.ConvertToAzureBatchJobId(sessionId)).ConfigureAwait(false); await this.UpdateSoaRelatedPropertiesAsync(sessionJob, properties).ConfigureAwait(false); } return(true); } catch (BatchException ex) { if (ex.RequestInformation != null && ex.RequestInformation.HttpStatusCode != null) { if (ex.RequestInformation.HttpStatusCode == HttpStatusCode.NotFound) { TraceHelper.TraceEvent(sessionId, TraceEventType.Warning, "[AzureBatchSchedulerDelegation] Can't update job properties because it can't be found in AzureBatch."); return(false); } } } catch (Exception ex) { TraceHelper.TraceEvent(TraceEventType.Error, ex.ToString()); } return(false); }
/// <summary> /// Initializes a new instance of the JobMonitorEntry class /// </summary> /// <param name="sessionid">indicating the session id</param> public AzureBatchJobMonitorEntry(string sessionid) { this.sessionid = sessionid; this.batchClient = AzureBatchConfiguration.GetBatchClient(); }