MedallionShell
MedallionShell copied to clipboard
Consider API for running a Command such that it will re-start on failure
This can be useful when managing long-running processes.
See https://github.com/madelson/MedallionShell/issues/26 as an example use-case.
Likely this would be implemented via a new option (RestartOnFailure(bool)). In such a case the ProcessId of the Command could change so we'd have to make sure that downstream IO and Pipe commands also pick up this change.
One weird thing is data being written to StdIn which could get split across process instances if the process crashes half-way through a write. Perhaps we could try to ensure that we'd always break on newline?
May I suggest allowing a pub-sub style event system that fires when these things happen?
i.e; OnBeforeRestart, OnAfterRestart and so on, so forth.
This should allow for a more robust third party integration.
@Wintereise can you give an example of how you would use those events? What kinds of actions would you take? What, if any, ancillary APIs would need to be available to make them work?
In my case, I would use them to clean up some things / set some internal flags before the restart triggered.
Something as simple as https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.iapplicationlifetime?view=aspnetcore-2.1 is enough for my needs, all I need to be able to do are register callbacks that get invoked as things happen.
As to ancillary API availability, that's a good question. Currently, I don't use any but a possible way to inject dependencies as required would be nice (DI integration may be way out of the scope of the project though).