Skip to content

Commit

Permalink
SIANXSVC-1186: Exit application after writing metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nachtjasmin committed Jan 31, 2024
1 parent 94eeafd commit d289e65
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Anexia.E5E/Hosting/E5EHostWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,20 @@ public async Task StartAsync(CancellationToken cancellationToken = default)
return;
}

string metadata = "";
#if NET8_0_OR_GREATER
metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(),
var metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(),
E5ESerializationContext.Default.E5ERuntimeMetadata);
#else
metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(), E5EJsonSerializerOptions.Default);
var metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(), E5EJsonSerializerOptions.Default);
#endif

_console.Open();
await _console.WriteToStdoutAsync(metadata).ConfigureAwait(false);
_console.Close();

// If we wrote the metadata, circumvent the default host mechanism as used by Run/RunAsync extensions
// and just stop the application.
_host.Services.GetRequiredService<IHostApplicationLifetime>().StopApplication();
// After we wrote the metadata, close the application immediately(!). Any startup tasks that occur after the startup
// (e.g. a long initialization task) won't be executed and the metadata is returned to e5e.
Environment.Exit(0);
}

public Task StopAsync(CancellationToken cancellationToken = default)
Expand Down

0 comments on commit d289e65

Please sign in to comment.