Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mnicolescu authored and mnicolescu committed Dec 4, 2018
1 parent 633825a commit 1210889
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ProcessMyMedia.Samples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace ProcessMyMedia.Samples
{
using System;
using System.IO;

using Microsoft.Extensions.Configuration;
Expand All @@ -16,7 +15,7 @@ static void Main(string[] args)

IConfigurationRoot configuration = builder.Build();

new Samples.AnalyseAsset(configuration).Execute();
new Samples.IngestFromDirectory(configuration).Execute();
}
}
}
3 changes: 3 additions & 0 deletions ProcessMyMedia/Tasks/Data/CopyTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ protected async override Task<ExecutionResult> RunTaskAsync(IStepExecutionContex
}
};

this.logger.LogDebug($"Create the pipeline for the Copy Task");

await this.service.CreateOrUpdatePipelineyAsync(pipeline);

runID = await this.service.RunPipelineAsync(pipeline.Name);
Expand All @@ -141,6 +143,7 @@ protected async override Task<ExecutionResult> RunTaskAsync(IStepExecutionContex
if (!this.Output.Run.IsFinished
|| context.PersistenceData == null)
{
this.logger.LogInformation("The copy is in progress.");
return ExecutionResult.Sleep(this.delayService.GetTimeToSleep(this.Output.Run.StartDate), this.Output);
}
else if (this.Output.Run.OnError)
Expand Down
2 changes: 2 additions & 0 deletions ProcessMyMedia/Tasks/Data/CreateLinkedServiceTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protected override void ValidateInput()
/// <returns></returns>
protected async override Task<ExecutionResult> RunTaskAsync(IStepExecutionContext context)
{
this.logger.LogInformation($"Create the Linked service {this.LinkedServiceToCreate.Name}");

await this.service.CreateOrUpdateLinkedServiceAsync(
this.LinkedServiceToCreate.Name,
this.LinkedServiceToCreate.Type,
Expand Down
4 changes: 4 additions & 0 deletions ProcessMyMedia/Tasks/Media/Analyzing/AnalyzeFileTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ protected async override Task RunMediaAnalyseTaskAsync(IStepExecutionContext con
{
string assetName = $"input-{Guid.NewGuid()}";

this.logger.LogInformation($"Create the asset {assetName}");

var asset = await service.CreateOrUpdateAssetAsync(assetName);

this.logger.LogDebug($"Upload the file {this.FilePath} for the asset {this.AssetName}");

await service.UploadFilesToAssetAsync(assetName, new[] { this.FilePath });

this.AssetName = assetName;
Expand Down
4 changes: 4 additions & 0 deletions ProcessMyMedia/Tasks/Media/Analyzing/AnalyzeTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ protected override async Task<ExecutionResult> RunTaskAsync(IStepExecutionContex
{
//First call: stat analyse
await this.RunMediaAnalyseTaskAsync(context);

this.logger.LogInformation($"Start analyse the asset {this.AssetName}");

job = await this.service.StartAnalyseAsync(this.AssetName, this.AnalyzingParameters);
}
else
Expand All @@ -75,6 +78,7 @@ protected override async Task<ExecutionResult> RunTaskAsync(IStepExecutionContex
if (!job.IsFinished)
{
this.logger.LogInformation($"Analysing progress : {job.Progress} %");

return ExecutionResult.Sleep(this.delayService.GetTimeToSleep(job.Created), job);
}
else if (job.Canceled)
Expand Down
2 changes: 2 additions & 0 deletions ProcessMyMedia/Tasks/Media/Asset/DeleteAssetTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected override void ValidateInput()
/// <returns></returns>
protected override async Task<ExecutionResult> RunTaskAsync(IStepExecutionContext context)
{
this.logger.LogInformation($"Delete the asset {this.AssetName}");

await this.service.DeleteAssetAsync(this.AssetName);

return ExecutionResult.Next();
Expand Down
2 changes: 2 additions & 0 deletions ProcessMyMedia/Tasks/Media/Asset/DownloadAssetTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protected override void ValidateInput()
/// <returns></returns>
protected async override Task<ExecutionResult> RunTaskAsync(IStepExecutionContext context)
{
this.logger.LogInformation($"Upload files from the asset {this.AssetName} to {this.DirectoryToDownload}");

await this.service.DownloadFilesAsync(this.AssetName, this.DirectoryToDownload);

return ExecutionResult.Next();
Expand Down
2 changes: 2 additions & 0 deletions ProcessMyMedia/Tasks/Media/Asset/IngestFilesTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protected override async Task<ExecutionResult> RunTaskAsync(IStepExecutionContex
{
await base.RunTaskAsync(context);

this.logger.LogDebug($"Upload {this.AssetFiles.Count} files for the asset {this.AssetName}");

await this.service.UploadFilesToAssetAsync(this.AssetName, this.AssetFiles, this.Metadata);

return ExecutionResult.Next();
Expand Down
2 changes: 2 additions & 0 deletions ProcessMyMedia/Tasks/Media/Asset/IngestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protected override void ValidateInput()
/// <returns></returns>
protected async override Task<ExecutionResult> RunTaskAsync(IStepExecutionContext context)
{
this.logger.LogInformation($"Create the asset {this.AssetName}");

AssetEntity asset = await this.service.CreateOrUpdateAssetAsync(this.AssetName,
assetDescription: this.AssetDescription,
storageAccountName: this.StorageAccountName);
Expand Down
4 changes: 4 additions & 0 deletions ProcessMyMedia/Tasks/Media/Encoding/EncodeFileTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ protected override async Task RunMediaEncodingTaskAsync(IStepExecutionContext co
{
string assetName = $"input-{Guid.NewGuid()}";

this.logger.LogInformation($"Create the encoding input asset {assetName} for the file {this.FilePath}");

var asset = await service.CreateOrUpdateAssetAsync(assetName);

this.logger.LogInformation($"Upload the file {this.FilePath} for the asset {assetName}");

await service.UploadFilesToAssetAsync(assetName, new[] { this.FilePath });

this.Inputs.Add (new JobInputEntity(){ Name = assetName});
Expand Down
3 changes: 3 additions & 0 deletions ProcessMyMedia/Tasks/Media/Encoding/EncodeTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ protected override async Task<ExecutionResult> RunTaskAsync(IStepExecutionContex
{
//First call: start encoding
await this.RunMediaEncodingTaskAsync(context);

this.logger.LogInformation("Start encoding");

job = await this.service.StartEncodeAsync(this.Inputs, this.Outputs, this.Priority);
}
else
Expand Down
8 changes: 7 additions & 1 deletion ProcessMyMedia/Tasks/TaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,25 @@ public override async Task<ExecutionResult> RunAsync(IStepExecutionContext conte

try
{
this.logger.LogDebug($"Task {this.GetType().Name} started");

var result = await this.RunTaskAsync(context);

if (this.CleanupResources && !result.SleepFor.HasValue)
{
await this.Cleanup(context);
}

this.logger.LogDebug($"Task {this.GetType().Name} completed");

return result;
}
catch
catch(Exception exc)
{
this.onError = true;

this.logger.LogError($"Task {this.GetType().Name} terminated with error {exc}");

if (this.CleanupResources)
{
await this.Cleanup(context);
Expand Down

0 comments on commit 1210889

Please sign in to comment.