Skip to content

ServiceWorker suggestions #58

@carsten-riedel

Description

@carsten-riedel

Hi,

nearly did the same, than found your project, nice work !!!

Regarding your Service Worker some suggestion, maybe it makes sense to use a BackgroundService ExecuteAsync and await for appLifetime.ApplicationStarted.
I don't like the fixed _hostLifetime.StopApplication(); either. I should be open who decides to quite the application, it could be done on a command level with _hostLifetime.StopApplication();
Maybe even individual configuration of the worker could be passed via UseSpectreConsole + Action< SpectreServiceWorkerConfig >

 public Task StartAsync(CancellationToken cancellationToken)
    {
        return Task.Factory.StartNew(async () =>
        {
            try
            {
                var args = GetArgs();
                await Task.Delay(100, cancellationToken); //Just to let Microsoft.Hosting finish.
                _exitCode = await _commandApp.RunAsync(args);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An unexpected error occurred");
                _exitCode = 1;
            }
            finally
            {
                _hostLifetime.StopApplication();
            }
        }, cancellationToken);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions