Repository navigation
Whole application should stop if any message system throws an error #63
Copy link
Copy link
Open
Description
Currently this code manages the application lifetime:
Lines 25 to 58 in 877144c
| let private startMessageSystem (system: IMessageSystem) receiver = | |
| Async.StartChild <| async { | |
| do! Async.SwitchToNewThread() | |
| try | |
| system.Run receiver | |
| with | |
| | ex -> logError ex | |
| } | |
| let private startApp config = | |
| async { | |
| printfn "Prepare system..." | |
| use system = ActorSystem.Create("emulsion") | |
| printfn "Prepare factories..." | |
| let restartContext = { | |
| cooldown = TimeSpan.FromSeconds(30.0) // TODO[F]: Customize through the config. | |
| logError = logError | |
| logMessage = logInfo | |
| } | |
| let! cancellationToken = Async.CancellationToken | |
| let xmpp = Xmpp.Client(restartContext, cancellationToken, config.xmpp) | |
| let telegram = Telegram.Client(restartContext, cancellationToken, config.telegram) | |
| let factories = { xmppFactory = Xmpp.spawn xmpp | |
| telegramFactory = Telegram.spawn telegram } | |
| printfn "Prepare Core..." | |
| let core = Core.spawn factories system "core" | |
| printfn "Starting message systems..." | |
| let! telegramSystem = startMessageSystem telegram core.Tell | |
| let! xmppSystem = startMessageSystem xmpp core.Tell | |
| printfn "Ready. Wait for termination..." | |
| do! Async.AwaitTask system.WhenTerminated | |
| printfn "Waiting for terminating of message systems..." | |
| do! telegramSystem | |
| do! xmppSystem |
As you can see, nothing stops any message system from completely failing (i.e. kill the child async started in startMessageSystem), but the actor system (i.e. the whole app) will still live.
We need to stop the whole application on critical failures (e.g. dead message system).
Take into account that throwing an error from a system.Run is a very unusual event: usually the message system will just restart itself without terminating Run.
Reactions are currently unavailable
Activity