I'm writing a console application that collects data from the websites (doing scraping). I make a webjob application in Visual Studio and contains my console application there and then I publish it in Azure App Service.
I tried to change settings in Web.config of my web job by adding
<add key="SCM_COMMAND_IDLE_TIMEOUT" value="3600" />
<add key="WEBJOBS_IDLE_TIMEOUT" value="3600" />
Also, I try to find where I can change the configuration of my web job app in the Azure portal and not really find it. reference to post Azure WebJob timeout configuration settings
This is the error that I received when I run it:
[08/19/2019 14:16:14 > 5a8697: SYS INFO] Status changed to Running
[08/19/2019 14:20:16 > 5a8697: ERR ] Command 'cmd /c ""MainApp.ex ...' was
aborted due to no output nor CPU activity for 121 seconds. You can
increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT
if this is a WebJob) if needed.
cmd /c ""MainApp.exe""
[08/19/2019 14:20:16 > 5a8697: SYS INFO] Status changed to Failed
example of scraping code:
public SiteProcessingResult ScrapeSite(string url, int siteId)
{
SiteProcessingResult result = new SiteProcessingResult();
int count = 0;
WebClient webRequest = new WebClient();
webRequest.Encoding = Encoding.UTF8;
string mainSiteHTML = webRequest.DownloadString(url);
mainSiteHTML = ScrapeHelper.RemoveComments(mainSiteHTML);
mainSiteHTML = mainSiteHTML.Substring(mainSiteHTML.IndexOf("<div class=\"wrap content\">"));
mainSiteHTML = mainSiteHTML.Remove(mainSiteHTML.IndexOf("<footer"));
string depReg = string.Format("{0}.*?{1}", "<div class=\"row\"", "@example.org</span>");
MatchCollection matchList = Regex.Matches(mainSiteHTML, depReg, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Singleline);
foreach (Match match in matchList)
{
string articleUrl = GetArticleUrl(match.ToString(), url);
string title = GetArticleTitle(match.ToString());
string organization = "";
string date = "";
string locationString = GetLocationFromArticle(match.ToString());
string content = GetContentFromArticle(match.ToString());
string state = GetState(locationString);
SitePost record = SitePost.CreateSiteRecord(date, content, title, articleUrl, jobTitle, organization, locationString, state, null, CultureInfo.CreateSpecificCulture("en-US"));
result.Records.Add(record);
}
return result;
}
example of sending mail:
public void SendEmail(SiteTypeEnum siteType, string subject, string message, bool isHtml = false, string sendTo = null)
{
string userName, password, to;
GetEmailLoginDetails(siteType, out userName, out password, out to);
if (sendTo == null)
{
sendTo = to;
}
LoggerHelper.WriteInfo("Send email, phase {0}, username {1}, password {2}, to {3}, subject {4}", siteType, userName, password, sendTo, subject);
Logic.Helper.EmailGoogle.SendMessage(sendTo, string.Empty, string.Empty, subject, message, isHtml, null, userName, password, userName, userName);
//SendEmailDev(phase2, subject, message, isHtml);
}