2017-05-01 48 views

回答

1

我建議你創建一個WebJob來測試你的API端點。在您的WebJob中,您可以使用TimerTrigger及時運行測試功能(例如,每2分鐘)。

要使用TimerTrigger,您需要使用NuGet安裝Microsoft.Azure.WebJobs.Extensions包。之後,您可以使用以下代碼將WebJob配置爲使用計時器擴展。

static void Main() 
{ 
    var config = new JobHostConfiguration(); 
    //Configure WebJob to use TimerTrigger 
    config.UseTimers(); 
    var host = new JobHost(config); 
    // The following code ensures that the WebJob will be running continuously 
    host.RunAndBlock(); 
} 

在函數中,您可以發送請求到您的Web API。如果您無法從服務器獲得響應,或者響應狀態不等於200 OK,則表示Web API不可用。

public static void StartupJob([TimerTrigger("0 */2 * * * *", RunOnStartup = true)] TimerInfo timerInfo) 
{ 
    WebRequest request = WebRequest.Create("URL of your api"); 
    HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
    if (response == null || response.StatusCode != HttpStatusCode.OK) 
    { 
     //API is not useable 
    } 
}