-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.fs
81 lines (64 loc) · 2.15 KB
/
Program.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
module WinTail.Program
open System
open System.Threading.Tasks
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Akka.Actor
open Akkling
open WinTail.Actors
type AkkaHostedService() =
let winTailConfig = Configuration.defaultConfig()
let winTailSystem = System.create "WinTailSystem" winTailConfig
let consoleWriterRef =
Actors.consoleWriter
|> actorOf2
|> props
|> spawn winTailSystem "ConsoleWriter"
let tailCoordinatorRef =
let actor = actorOf2 Actors.tailCoordinator
let super =
Strategy.OneForOne(
fun ex ->
match ex with
| :? NotSupportedException -> Directive.Stop
| _ -> Directive.Resume
, 3
, TimeSpan.FromSeconds(30.0)
)
let props = { props actor with SupervisionStrategy = Some super }
spawn winTailSystem "TailCoordinator" props
let inputValidatorRef =
Actors.inputValidator consoleWriterRef
|> actorOf2
|> props
|> spawn winTailSystem "InputValidator"
let consoleReaderRef =
Actors.consoleReader
|> actorOf2
|> props
|> spawn winTailSystem "ConsoleReader"
interface IHostedService with
member this.StartAsync(cancellation) =
Console.WriteLine "Enter the path to the file you want to tail:"
consoleReaderRef <! Messages.ReadInput
Task.CompletedTask
member this.StopAsync(cancellation) =
winTailSystem.Terminate()
interface IDisposable with
member this.Dispose() =
winTailSystem.Dispose()
[<EntryPoint>]
let main args =
HostBuilder()
.ConfigureServices(fun collection ->
collection
.Configure<ConsoleLifetimeOptions>(fun options ->
options.SuppressStatusMessages <- true
)
.AddHostedService<AkkaHostedService>()
|> ignore
)
.UseConsoleLifetime()
.Build()
.Run()
0 // return an integer exit code