Reputation: 160
Can I actually deploy F# console app as Azure WebJob? Can't find a proper option in VS2017 :(
And if it's possible, can you have a look at my code? Would it work as it is if I will deploy it as AzureWebJob? Do I need to change something?
open FSharp.Data;
open System
open System.Net.Mail
let server = "smtp.gmail.com"
let sender = "[email protected]"
let password = "password"
let port = 587
let SendTest email topic msg =
use msg =
new MailMessage(
sender, email, topic,
msg)
let client = new SmtpClient(server, port)
client.EnableSsl <- true
client.Timeout <- 20000
client.DeliveryMethod <- SmtpDeliveryMethod.Network
client.UseDefaultCredentials <- false
client.Credentials <- System.Net.NetworkCredential(sender, password)
client.Send msg
let metaTitle (doc:HtmlDocument) =
doc.Descendants "meta"
|> Seq.choose (fun x ->
match x.AttributeValue("name"), x.AttributeValue("property") with
| "title", _
| "headline", _
| "twitter:title", _
| _, "og:title" ->
Some(x.AttributeValue("content"))
| _, _ -> None
)
let titles (doc:HtmlDocument) =
let tagged (tag:string) =
doc.Descendants tag |> Seq.map (fun x -> x.InnerText())
Seq.concat [tagged "title"; metaTitle doc; tagged "h1"]
let title (doc:HtmlDocument) =
titles doc |> Seq.tryHead
let finalTitle (link:string) = try
link
|> HtmlDocument.Load
|> titles
|> Seq.head
with
| :? Exception as ex -> ex.Message
[<EntryPoint>]
let main argv =
let website = "website.com"
if(finalTitle website <> "expected title")
then
SendTest "[email protected]" "Status: Failed" (website + " is down :( ")
0 // return an integer exit code
Upvotes: 1
Views: 172
Reputation: 24569
Can I actually deploy F# console app as Azure WebJob?
Yes, we can delploy F# console app as Azure WebJob
Can't find a proper option in VS2017
Publish F# project as Azure webjob from VS2017 tool directly is not supported currently.
But we can publish the F# project from Azure Portal.I did a demo for it. The following is my detail steps:
1.Create F# project with VS2017
2.Install the WebJob SKD in the project
3.Build the project and Zip the release or debug file in the bin folder
4.Upload the Zip file from Azure portal
5.Config the Appsetting with Storage connection string
6.Check the webjob with Azure Kudu(https://yourwebsite.scm.azurewebsites.net) tool
Upvotes: 1
Reputation: 18387
You need to create an .exe from your f# code, create a zip from the output folder and upload it to Azure.
https://blogs.msdn.microsoft.com/dave_crooks_dev_blog/2015/02/18/deploying-f-web-job-to-azure/
Another option is use Azure Functions which is the evolution of Azure WebJobs and has support for f#: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-fsharp
Upvotes: 1