-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.fs
36 lines (32 loc) · 1.12 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
// For more information see https://aka.ms/fsharp-console-apps
open System
open MySqlConnector
open ConnectionString
let connectionString = sprintf "Server=%s;Port=%d;Database=%s;User ID=%s;Password=%s" DBHost DBPort DBSchema DBUser DBPass
let checkDbPing () =
try
use conn = new MySqlConnection(connectionString)
conn.Open()
use cmd = new MySqlCommand("SELECT 1", conn)
cmd.ExecuteScalar() |> ignore
printfn "Database ping successful."
true
with
| ex ->
printfn "Failed to ping database: %s" ex.Message
false
let rec heartbeatLoop () =
let result = checkDbPing()
let timeNow = System.DateTime.Now.ToString("ddd dd/MMM/yyyy HH:mm:ss")
if result then
printfn "Heartbeat: Database is reachable at %s." timeNow
else
printfn "Heartbeat: Database is inaccesible at %s." timeNow
let sleepIntervalMinutes = 10
System.Threading.Thread.Sleep(sleepIntervalMinutes * 60 * 1000)
heartbeatLoop()
[<EntryPoint>]
let main argv =
printfn "Starting heartbeat service..."
heartbeatLoop()
0