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

moved azure hack under env variable for a better dev UX #18

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions src/Grinder/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,32 @@ module Program =
sprintf "Error on upserting new users %A" users
|> logExn e
)
}
}

let azureLoop(botAsync: Async<Unit>) =
botAsync
|> Async.Start

logInfo "Bot started"

// Needed for azure web app deploy check. We have to response with anything on port 80
use listener = new HttpListener()
listener.Prefixes.Add("http://*:80/")
listener.Start()

let buffer = System.Text.Encoding.UTF8.GetBytes "OK"

while true do
let ctx = listener.GetContext()
let output = ctx.Response.OutputStream
output.Write(buffer, 0, buffer.Length)
output.Close()
logInfo "Sending OK on HTTP request"

let localLoop(botAsync: Async<Unit>) =
logInfo "Bot started"
botAsync
|> Async.RunSynchronously

let onUpdate (settings: BotSettings) (botApi: IBotApi) (dataApi: IDataAccessApi) (context: UpdateContext) =
async {
Expand Down Expand Up @@ -272,24 +297,14 @@ module Program =
|> logInfo

logInfo "Starting bot"
startBot botConfiguration (onUpdate settings (createBotApi botConfiguration settings) dataApi) None
|> Async.Start
let bot = startBot botConfiguration (onUpdate settings (createBotApi botConfiguration settings) dataApi) None

logInfo "Bot started"

// Needed for azure web app deploy check. We have to response with anything on port 80
use listener = new HttpListener()
listener.Prefixes.Add("http://*:80/")
listener.Start()

let buffer = System.Text.Encoding.UTF8.GetBytes "OK"

while true do
let ctx = listener.GetContext()
let output = ctx.Response.OutputStream
output.Write(buffer, 0, buffer.Length)
output.Close()
logInfo "Sending OK on HTTP request"
match Environment.GetEnvironmentVariable("DOTNETRU_IS_AZURE") with
| null -> localLoop bot
| isAzureStr ->
match bool.TryParse isAzureStr with
| true, true -> azureLoop bot
| _ -> localLoop bot

logInfo "Bot exited"
0 // return an integer exit code
0 // return an integer exit code