Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bored... #195

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions EtLast.CommandService/CommandService.RunTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,33 @@ protected override IExecutionResult RunTasks(string commandId, string moduleName
Tasks = tasks.ToArray(),
};

startup?.Invoke(sessionBuilder, arguments);

foreach (var configurator in SessionConfigurators)
configurator?.Invoke(sessionBuilder, arguments);

startup?.Invoke(sessionBuilder, arguments);

if (moduleName != null)
context.Manifest.Extra["ModuleName"] = moduleName;

context.Manifest.Extra["TaskNames"] = tasks.Select(x => x.GetType().GetFriendlyTypeName()).ToArray();

foreach (var manifestProcessor in sessionBuilder.ManifestProcessors)
manifestProcessor?.RegisterToManifestEvents(context, context.Manifest);
if (sessionBuilder.ManifestProcessorCreators?.Count > 0)
{
try
{
foreach (var creator in sessionBuilder.ManifestProcessorCreators)
{
var manifestProcessor = creator?.Invoke();
manifestProcessor?.RegisterToManifestEvents(context, context.Manifest);
}
}
catch (Exception ex)
{
var formattedMessage = ex.Format();
context.Log(LogSeverity.Error, null, "{ErrorMessage}", formattedMessage);
context.LogOps(LogSeverity.Error, null, "{ErrorMessage}", formattedMessage);
}
}

if (sessionBuilder.EtlContextLoggerCreators?.Count > 0)
{
Expand All @@ -64,7 +79,7 @@ protected override IExecutionResult RunTasks(string commandId, string moduleName
}
catch (Exception ex)
{
var formattedMessage = ex.FormatWithEtlDetails();
var formattedMessage = ex.Format();
context.Log(LogSeverity.Error, null, "{ErrorMessage}", formattedMessage);
context.LogOps(LogSeverity.Error, null, "{ErrorMessage}", formattedMessage);
}
Expand Down
2 changes: 1 addition & 1 deletion EtLast.CommandService/SessionBuilderFluent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static ISessionBuilder UseRollingDevLogManifestFiles(this ISessionBuilder
var directory = Path.Combine(session.DevLogDirectory, "manifest");
CleanupManifestDirectory(maxFileCount, maxSizeOnDisk, directory);

return session.AddManifestProcessor(new CommandServiceJsonManifestProcessor()
return session.AddManifestProcessor(() => new CommandServiceJsonManifestProcessor()
{
Directory = directory,
FileNameGenerator = manifest => manifest.ContextId.ToString("D", CultureInfo.InvariantCulture) + ".json",
Expand Down
32 changes: 2 additions & 30 deletions EtLast.Hosting/Logging/EtlContextConsoleLogger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace FizzCode.EtLast;

internal class EtlContextConsoleLogger : IEtlContextListener
internal class EtlContextConsoleLogger : IEtlContextLogger
{
private readonly ILogger _logger;

Expand Down Expand Up @@ -84,34 +84,6 @@ public void OnContextIoCommandEnd(IoCommand ioCommand)
{
}

public void OnRowCreated(IReadOnlyRow row)
{
}

public void OnRowOwnerChanged(IReadOnlyRow row, IProcess previousProcess, IProcess currentProcess)
{
}

public void OnRowValueChanged(IReadOnlyRow row, params KeyValuePair<string, object>[] values)
{
}

public void OnSinkStarted(IProcess process, Sink sink)
{
}

public void OnWriteToSink(Sink sink, IReadOnlyRow row)
{
}

public void OnProcessStart(IProcess process)
{
}

public void OnProcessEnd(IProcess process)
{
}

public void OnContextClosed()
{
try
Expand All @@ -127,7 +99,7 @@ public static class EtlContextConsoleLoggerFluent
{
public static ISessionBuilder LogToConsole(this ISessionBuilder builder, LogSeverity minimumLogLevel = LogSeverity.Information)
{
builder.Context.Listeners.Add(new EtlContextConsoleLogger(builder.Context, minimumLogLevel));
builder.Context.Loggers.Add(new EtlContextConsoleLogger(builder.Context, minimumLogLevel));
return builder;
}
}
2 changes: 1 addition & 1 deletion EtLast.Hosting/Logging/EtlContextDevToFileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public static class EtlContextDevToFileLoggerFluent
{
public static ISessionBuilder LogDevToFile(this ISessionBuilder builder, LogSeverity minimumLogLevel = LogSeverity.Debug, int retentionHours = 24 * 31)
{
builder.AddLoggerCreator(() => new EtlContextDevToFileLogger(builder.Context, builder.DevLogDirectory, minimumLogLevel, retentionHours));
builder.AddLogger(() => new EtlContextDevToFileLogger(builder.Context, builder.DevLogDirectory, minimumLogLevel, retentionHours));
return builder;
}
}
2 changes: 1 addition & 1 deletion EtLast.Hosting/Logging/EtlContextDevToSeqLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static class EtlContextDevToSeqLoggerFluent
{
public static ISessionBuilder LogDevToSeq(this ISessionBuilder session, string url, string apiKey, LogSeverity minimumLogLevel = LogSeverity.Debug)
{
session.AddLoggerCreator(() => new EtlContextDevToSeqLogger(session.Context, url, apiKey, minimumLogLevel));
session.AddLogger(() => new EtlContextDevToSeqLogger(session.Context, url, apiKey, minimumLogLevel));
return session;
}
}
2 changes: 1 addition & 1 deletion EtLast.Hosting/Logging/EtlContextOpsToFileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static class EtlContextOpsToFileLoggerFluent
{
public static ISessionBuilder LogOpsToFile(this ISessionBuilder session, int importantFileCount = 30, int infoFileCount = 14)
{
session.AddLoggerCreator(() => new EtlContextOpsToFileLogger(session.Context, session.OpsLogDirectory, importantFileCount, infoFileCount));
session.AddLogger(() => new EtlContextOpsToFileLogger(session.Context, session.OpsLogDirectory, importantFileCount, infoFileCount));
return session;
}
}
4 changes: 2 additions & 2 deletions EtLast/Session/ISessionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ISessionBuilder
public string DevLogDirectory { get; }
public string OpsLogDirectory { get; }

public ISessionBuilder AddManifestProcessor(IManifestProcessor manifestProcessor);
public ISessionBuilder AddLoggerCreator(Func<IEtlContextLogger> creator);
public ISessionBuilder AddManifestProcessor(Func<IManifestProcessor> manifestProcessor);
public ISessionBuilder AddLogger(Func<IEtlContextLogger> creator);
public ISessionBuilder UseTransactionScopeTimeout(TimeSpan timeout);
}
8 changes: 4 additions & 4 deletions EtLast/Session/SessionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public class SessionBuilder : ISessionBuilder
public required string DevLogDirectory { get; init; }
public required string OpsLogDirectory { get; init; }

public List<IManifestProcessor> ManifestProcessors { get; } = [];
public List<Func<IManifestProcessor>> ManifestProcessorCreators { get; } = [];

[EditorBrowsable(EditorBrowsableState.Never)]
public List<Func<IEtlContextLogger>> EtlContextLoggerCreators { get; } = [];

public ISessionBuilder AddManifestProcessor(IManifestProcessor manifestProcessor)
public ISessionBuilder AddManifestProcessor(Func<IManifestProcessor> manifestProcessor)
{
ManifestProcessors.Add(manifestProcessor);
ManifestProcessorCreators.Add(manifestProcessor);
return this;
}

public ISessionBuilder AddLoggerCreator(Func<IEtlContextLogger> creator)
public ISessionBuilder AddLogger(Func<IEtlContextLogger> creator)
{
EtlContextLoggerCreators.Add(creator);
return this;
Expand Down
2 changes: 1 addition & 1 deletion EtLast/Telemetry/ContextManifest/IManifestProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
public interface IManifestProcessor
{
public void RegisterToManifestEvents(IEtlContext context, ContextManifest manifest);
}
}
Loading