【发布时间】:2016-02-03 09:25:49
【问题描述】:
我正在尝试构建一个 Azure WebJob 以每 5 分钟检查一次网站的状态。我将工作构建为一个运行良好的控制台应用程序。运行时,它将查询 MySQL 数据库以获取网站列表,向网站提交 HTTP 请求,然后在 MySQL 数据库中记录该请求的状态。就像我说的,从控制台,这工作得很好。当我将其压缩并添加为 Web 作业时,我的程序中运行 Ping 以获取响应时间的部分失败了。我运行 ping 的代码是:
public ArrayList GetStatusList(ArrayList sites)
{
foreach (Website ws in sites)
{
HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(ws.WebsiteUrl);
webRequest.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse) webRequest.GetResponse();
ws.HttpStatus = response.StatusCode.ToString();
Uri uri = new Uri(ws.WebsiteUrl);
Ping pingClass = new Ping();
PingReply pingReply = pingClass.Send(uri.Host);
ws.ResponseTime = pingReply.RoundtripTime;
ws.WebsiteCheckedDateTime = DateTime.Now;
}
下面是来自 Azure WebJob 的错误日志:
[02/01/2016 19:33:37 > c91ef2: SYS INFO] Status changed to Stopped
[02/01/2016 19:33:57 > c91ef2: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob
[02/01/2016 19:33:57 > c91ef2: SYS INFO] Status changed to Starting
[02/01/2016 19:33:57 > c91ef2: SYS WARN] 'Always On' doesn't appear to be enabled for this Web App. To ensure your continuous job doesn't stop running when the SCM host is idle for too long, consider enabling 'Always On' in the configuration settings for your Web App. Note: 'Always On' is available only in Basic, Standard and Premium modes.
[02/01/2016 19:33:57 > c91ef2: SYS INFO] Run script 'IsItAlive.exe' with script host - 'WindowsScriptHost'
[02/01/2016 19:33:57 > c91ef2: SYS INFO] Status changed to Running
[02/01/2016 19:33:58 > c91ef2: INFO] Connected to DB, MySQL version : 5.5.45-log
[02/01/2016 19:33:58 > c91ef2: ERR ]
[02/01/2016 19:33:58 > c91ef2: ERR ] Unhandled Exception: System.Net.NetworkInformation.PingException: An exception occurred during a Ping request. ---> System.ComponentModel.Win32Exception: There are no more endpoints available from the endpoint mapper
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.InternalSend(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options, Boolean async)
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.Send(IPAddress address, Int32 timeout, Byte[] buffer, PingOptions options)
[02/01/2016 19:33:58 > c91ef2: ERR ] --- End of inner exception stack trace ---
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.Send(IPAddress address, Int32 timeout, Byte[] buffer, PingOptions options)
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress)
[02/01/2016 19:33:58 > c91ef2: ERR ] at IsItAlive.BusinessLogic.GetStatusOfSites.GetStatusList(ArrayList sites)
[02/01/2016 19:33:58 > c91ef2: ERR ] at IsItAlive.Program.Main(String[] args)
[02/01/2016 19:33:58 > c91ef2: SYS ERR ] Job failed due to exit code -532462766
[02/01/2016 19:33:58 > c91ef2: SYS INFO] Process went down, waiting for 60 seconds
[02/01/2016 19:33:58 > c91ef2: SYS INFO] Status changed to PendingRestart
我确信答案就在我面前,但我只是没有足够的经验来理解错误日志。谁能帮我理解为什么我的 Ping 在作为 WebJob 而不是作为控制台应用程序运行时会导致 Ping 异常?
【问题讨论】: