With an ASP.NET MVC controller, I call a function runPreflighter
that runs a task. This task loops on a set of given files, runs them through an external rest API, reads a log file, and updates a database with the the results.
Occasionally, the task fails silently, and calls update the database with the error/emails to send to users with the error do not complete.
Running the same files later on completes the task successfully.
I am struggling to find out why the task fails without notice. Is there a way to attach to a task after it ran to see what it’s doing? Even when the API is deployed?
public static int runPreflighter(List<string> torun, int techID, string forcedEnv, preFlighterRunData runData, string sendEmail, string email)
{
int runid = PTADB.startAsyncJob(techid, PTADB.getPreflighterId(forcedEnv), forcedEnv);
Task.Run(() =>
{
try
{
foreach (string file in torun)
{
string preflightlog = Path.Combine(Path.GetDirectoryName(file), "Preflight_" + Path.GetFileNameWithoutExtension(file) + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".log");
string preflightCmdLine = string.Format("-s {0} -p {1} "{2}" ", runData.inspireServer, runData.inspirePort, runData.wfdFile);
preflightCmdLine += string.Format(" -warningconfig "vcs:\\Job Settings\WarningConfigs\9078.wpr" -e NULL -useincluded "*" -l "{0}" ", preflightlog);
PTADB.updateRunDetails(runid, "", "", "", "Preflighting for " + file, forcedEnv);
try
{
ToolRunStatus status = new ToolRunStatus { toolrunid = runid, job = "", sub = "", cycle = "", status = "Preflighting for " + file };
Ignite.runCommandLineAsBatch(runData.inspireServerFile, preflightCmdLine, file, "", "", "", "", "", forcedEnv, runData.hamburg, false, status);
}
catch (Exception ex)
{
}
// mysteriously & randomly fails here, i.e. file 6 of 9
}
PTADB.endAsyncJob(runid, 'Y', "", forcedEnv);
}
catch (Exception ex)
{
// Update Database with error result, send email to user
PTADB.endAsyncJob(runid, 'N', ex.Message, forcedEnv);
// Send email to user that this failed
List<string> to = new List<string> { email };
string message = string.Format("Preflight failed for WFD {0} - {1}", runData.wfdFile, ex.Message);
string subject = string.Format("Failed: Preflighter Encountered an error for {0}", runData.wfdFile);
Email.sendEmail(subject, message, to);
}
});
return runid;
}
3