Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ForNeVeR opened this issue Jul 20, 2019 · 0 comments
Open

Comments

@ForNeVeR
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant