public void FinishSubtask(string machineName, string agentName, SnSubtask subtask, SnTask task) { SnTrace.TaskManagement.Write("AgentHub FinishSubtask. Task id:{0}, agent:{1}, title:{2}", task.Id, agentName, subtask.Title); try { TaskDataHandler.FinishSubtask(machineName, agentName, subtask, task); TaskMonitorHub.OnTaskEvent(SnTaskEvent.CreateSubtaskFinishedEvent(task.Id, subtask.Title, subtask.Details, task.AppId, task.Tag, machineName, agentName, subtask.Id)); } catch (Exception ex) { SnLog.WriteException(ex, "AgentHub FinishSubtask failed.", EventId.TaskManagement.General); } }
public async Task FinishSubtask(string machineName, string agentName, SnSubtask subtask, SnTask task) { SnTrace.TaskManagement.Write("AgentHub FinishSubtask. Task id:{0}, agent:{1}, title:{2}", task.Id, agentName, subtask.Title); try { await _dataHandler.FinishSubtask(machineName, agentName, subtask, task, Context.ConnectionAborted).ConfigureAwait(false); await _monitorHub.OnTaskEvent(SnTaskEvent.CreateSubtaskFinishedEvent(task.Id, subtask.Title, subtask.Details, task.AppId, task.Tag, machineName, agentName, subtask.Id)).ConfigureAwait(false); } catch (Exception ex) { SnLog.WriteException(ex, "AgentHub FinishSubtask failed.", EventId.TaskManagement.General); } }
static void Main(string[] args) { var subtask = new SnSubtask("Thinking hard", "Pretending to do something."); subtask.Start(); var count = new Random().Next(10, 15); for (var i = 0; i < count; i++) { Thread.Sleep(1000); subtask.Progress(i, count, i, count, $"Still pretending: {i}..."); } subtask.Finish("Cannot pretend anymore."); }
// ================================================================================================== Preview generation private static async Task GenerateImagesAsync(CancellationToken cancellationToken) { int previewsFolderId; string contentPath; var downloadingSubtask = new SnSubtask("Downloading", "Downloading file and other information"); downloadingSubtask.Start(); try { var fileInfo = await GetFileInfoAsync().ConfigureAwait(false); if (fileInfo == null) { Logger.WriteWarning(ContentId, 0, "Content not found."); downloadingSubtask.Finish(); return; } cancellationToken.ThrowIfCancellationRequested(); previewsFolderId = await GetPreviewsFolderIdAsync(); if (previewsFolderId < 1) { Logger.WriteWarning(ContentId, 0, "Previews folder not found, maybe the content is missing."); downloadingSubtask.Finish(); return; } downloadingSubtask.Progress(10, 100, 2, 110, "File info downloaded."); cancellationToken.ThrowIfCancellationRequested(); contentPath = fileInfo.Path; if (Config.ImageGeneration.CheckLicense) { CheckLicense(contentPath.Substring(contentPath.LastIndexOf('/') + 1)); } } catch (Exception ex) { Logger.WriteError(ContentId, message: "Error during initialization. The process will exit without generating images.", ex: ex, startIndex: StartIndex, version: Version); return; } #region For tests //if (contentPath.EndsWith("freeze.txt", StringComparison.OrdinalIgnoreCase)) // Freeze(); //if (contentPath.EndsWith("overflow.txt", StringComparison.OrdinalIgnoreCase)) // Overflow(); #endregion await using var docStream = await GetBinaryAsync(); if (docStream == null) { Logger.WriteWarning(ContentId, 0, $"Document not found; maybe the content or its version {Version} is missing."); downloadingSubtask.Finish(); return; } downloadingSubtask.Progress(100, 100, 10, 110, "File downloaded."); cancellationToken.ThrowIfCancellationRequested(); if (docStream.Length == 0) { await SetPreviewStatusAsync(0); // PreviewStatus.EmptyDocument downloadingSubtask.Finish(); return; } downloadingSubtask.Finish(); _generatingPreviewSubtask = new SnSubtask("Generating images"); _generatingPreviewSubtask.Start(); var extension = contentPath.Substring(contentPath.LastIndexOf('.')); await PreviewImageGenerator.GeneratePreviewAsync(extension, docStream, new PreviewGenerationContext( ContentId, previewsFolderId, StartIndex, MaxPreviewCount, Config.ImageGeneration.PreviewResolution, Version), cancellationToken).ConfigureAwait(false); _generatingPreviewSubtask.Finish(); }
private static void WriteFinishSubtaskEvent(SnSubtask subtask, SnTask task, string machine, string agent) { WriteEvent(null, TaskEventType.SubtaskFinished, task.Id, subtask.Id, subtask.Title, subtask.Details, task.AppId, machine, agent, task.Tag , null, null, null, null); }
public static void FinishSubtask(string machineName, string agentName, SnSubtask subtask, SnTask task) { WriteFinishSubtaskEvent(subtask, task, machineName, agentName); }
private Task WriteFinishSubtaskEventAsync(SnSubtask subtask, SnTask task, string machine, string agent, CancellationToken cancellationToken) { return(WriteEventAsync(null, TaskEventType.SubtaskFinished, task.Id, subtask.Id, subtask.Title, subtask.Details, task.AppId, machine, agent, task.Tag , null, null, null, null, cancellationToken)); }
public Task FinishSubtask(string machineName, string agentName, SnSubtask subtask, SnTask task, CancellationToken cancellationToken) { return(WriteFinishSubtaskEventAsync(subtask, task, machineName, agentName, cancellationToken)); }
// ================================================================================================== Preview generation protected static void GenerateImages() { int previewsFolderId; string contentPath; var downloadingSubtask = new SnSubtask("Downloading", "Downloading file and other information"); downloadingSubtask.Start(); try { previewsFolderId = GetPreviewsFolderId(); if (previewsFolderId < 1) { Logger.WriteWarning(ContentId, 0, "Previews folder not found, maybe the content is missing."); downloadingSubtask.Finish(); return; } var fileInfo = GetFileInfo(); if (fileInfo == null) { Logger.WriteWarning(ContentId, 0, "Content not found."); downloadingSubtask.Finish(); return; } downloadingSubtask.Progress(10, 100, 2, 110, "File info downloaded."); contentPath = fileInfo["Path"].Value <string>(); CheckLicense(contentPath.Substring(contentPath.LastIndexOf('/') + 1)); } catch (Exception ex) { Logger.WriteError(ContentId, message: "Error during initialization. The process will exit without generating images.", ex: ex, startIndex: StartIndex, version: Version); return; } //if (contentPath.EndsWith("freeze.txt", StringComparison.OrdinalIgnoreCase)) // Freeze(); //if (contentPath.EndsWith("overflow.txt", StringComparison.OrdinalIgnoreCase)) // Overflow(); using (var docStream = GetBinary()) { if (docStream == null) { Logger.WriteWarning(ContentId, 0, string.Format("Document not found; maybe the content or its version {0} is missing.", Version)); downloadingSubtask.Finish(); return; } downloadingSubtask.Progress(100, 100, 10, 110, "File downloaded."); if (docStream.Length == 0) { SetPreviewStatus(0); // PreviewStatus.EmptyDocument downloadingSubtask.Finish(); return; } downloadingSubtask.Finish(); _generatingPreviewSubtask = new SnSubtask("Generating images"); _generatingPreviewSubtask.Start(); var extension = contentPath.Substring(contentPath.LastIndexOf('.')); PreviewImageGenerator.GeneratePreview(extension, docStream, new PreviewGenerationContext( ContentId, previewsFolderId, StartIndex, MaxPreviewCount, Configuration.PreviewResolution, Version)); _generatingPreviewSubtask.Finish(); } }