2017-04-13 270 views
1

我可以實際部署F#控制檯應用程序作爲Azure WebJob嗎?在VS2017中找不到合適的選項:(如何部署F#Azure WebJob?

如果可能的話,你能看看我的代碼嗎?它會像我將它部署爲AzureWebJob那樣工作嗎?我需要改變一些東西嗎?

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 

回答

1

我可以實際部署F#控制檯應用程序作爲Azure WebJob嗎?

是的,我們可以delploy F#控制檯應用程序,如天青WebJob

找不到在VS2017一個合適的選擇

發佈F#項目從VS2017工具Azure的webjob不能直接使用目前支持。

但是我們可以從Azure Portal發佈F#項目。我爲它做了一個演示。以下是我的詳細步驟:

1.創建f讓VS2017#項目

enter image description here

2.安裝的WebJob SKD項目

enter image description here

3.Build項目和Zip文件夾中的發佈或調試文件

enter image description here

4.Upload從Azure的門戶

enter image description here

5.Config的Appsetting與存儲連接字符串

enter image description here

6.檢查與天青捻的webjob Zip文件(https://yourwebsite.scm.azurewebsites.net )工具

enter image description here

+0

很好的答案,謝謝! –