Пример #1
0
        /// <summary>
        /// Check queued alerts. Several of these process may be running at the same time in parallel.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>

        public static string CheckQueuedAlerts(
            string args)
        {
            string msg;
            int    i1;
            bool   forceCheck        = false;
            bool   checkOnly         = false;
            int    firstToCheck      = 0;
            bool   hasMoreAlerts     = true;
            int    alertsWithNewData = 0;
            int    alertsChecked     = 0;

            string processorIdTxt = ", Pid: " + (int)DateTime.Now.TimeOfDay.TotalSeconds;             // mark each message with id of processor (sec of day started)

            AlertUtil.LogAlertMessage("Queue processor started: " + args + processorIdTxt);

            if (args != null && args.Trim().Length > 0)
            {
                if (Lex.Contains(args, "forceCheck"))
                {
                    forceCheck = true;
                }
                if (Lex.Contains(args, "checkOnly"))
                {
                    checkOnly = true;
                }
            }

            string alertQueueFileName = GetAlertQueueFileName();

            while (hasMoreAlerts)
            {
                UserObject uo = GetNextAlert(processorIdTxt, alertQueueFileName);
                if (uo == null)
                {
                    break;
                }

                int queryId = 0;                 // get queryId from alert name
                i1 = uo.Name.IndexOf("_");
                if (i1 > 0)
                {
                    try { queryId = Int32.Parse(uo.Name.Substring(i1 + 1)); }
                    catch (Exception) { }
                }

                msg = "Processing Alert: " + uo.Id +
                      ", QueryId: " + queryId + processorIdTxt;
                //			Thread.Sleep(10000); // debug
                AlertUtil.LogAlertMessage(msg);
                Progress.Show(msg);

                DateTime begin = DateTime.Now;
                try                 // check it
                {
                    msg = AlertUtil.Check(uo, forceCheck, checkOnly, false);
                }
                catch (Exception ex)
                {
                    msg = "Error executing Alert: " + uo.Id +
                          ", QueryId: " + queryId + ", Processor: " + processorIdTxt;

                    if (Lex.Contains(ex.Message, "ORA-01012") || Lex.Contains(ex.Message, "ORA-00028"))
                    {
                        msg += ", Error: " + ex.Message; // keep simple if forced logoff
                    }
                    else                                 // include stack trace otherwise
                    {
                        msg += "Error: " + DebugLog.FormatExceptionMessage(ex, msg);
                    }

                    AlertUtil.LogAlertMessage(msg);
                    AlertUtil.LogAlertErrorMessage(msg);
                    alertsChecked++;
                    continue;
                }

                if (Lex.Contains(msg, "Delayed Alert"))
                {
                    AlertUtil.LogAlertMessage(msg);
                    Alert alert = Alert.GetAlertFromUserObject(uo, true);
                    AddAlertBack(alert);
                    SleepUntilNextAlertStartTime(uo);
                    continue;
                }

                string msg0 =                  // message prefix
                              "Completed Alert: " + uo.Id + ", QueryId: " + queryId + processorIdTxt;

                //DateTime end = DateTime.Now; // (redundant)
                //TimeSpan elapsed = end.Subtract(begin);
                //string eTxt = elapsed.ToString();
                //if ((i1 = eTxt.IndexOf(".")) > 0) eTxt = eTxt.Substring(0, i1);
                //msg0 += ", Time to process = " + eTxt;

                msg = msg0 + " " + msg;
                AlertUtil.LogAlertMessage(msg);

                if (Lex.Contains(msg, "Error executing alert"))                 // keep separate log of errors
                {
                    AlertUtil.LogAlertErrorMessage(msg);
                }

                alertsChecked++;
                if (msg.Contains("Changed compounds"))
                {
                    alertsWithNewData++;
                }
            }

            msg = "Queue processor complete, Alerts checked: " + alertsChecked +
                  ", Alert E-mails: " + alertsWithNewData + processorIdTxt;

            AlertUtil.LogAlertMessage("");
            AlertUtil.LogAlertMessage(msg);
            Progress.Hide();
            return(msg);
        }