Skip to content

Whole application should stop if any message system throws an error #63

@ForNeVeR

Description

@ForNeVeR

Currently this code manages the application lifetime:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions