Exemple #1
0
        public void ProcessQueue()
        {
            int JobKey = -1;

            try
            {
                // Validate the processing job and update those that are no long running.
                ValidateRunningJobs();
                // Check for any scheduled work
                CheckScheduledJobs();
                // Check for any queued work
                DataRow dr = GetNextJob();
                if (dr == null)
                {
                    return;
                }

                JobKey = MiscUtilities.ObjectToInteger(dr["pkey"], "No primary key is definied");
                String JobFileName      = MiscUtilities.ObjectToString(dr["definition_name"], "No definition file name is defined.");
                String RawJobFileName   = JobFileName;
                String lockFilename     = MiscUtilities.LockFilename(RawJobFileName);
                String action_requested = MiscUtilities.ObjectToStringDefault(dr["action_requested"], "rescan");

                using (FileStream fs = new FileStream(lockFilename, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("While file is locked open, processing thread is running.  Seeing this message means the thread may not be running, please delete this file.");
                        if (_IsDbBackup)
                        {
                            BackupCastDatabase(JobKey, JobFileName, RawJobFileName);
                        }
                        else
                        {
                            String message = "Processing";
                            switch (action_requested.ToLower())
                            {
                            case "publish":
                                JobFileName = _tokens.Resolve("Scheduler", "PublishDefinition", "No publish definition defined in the settings file.  Please add a Tokens/Scheduler PublishDefinition");
                                message     = "Publishing";
                                break;

                            case "empty":
                            case "rescan":
                                message = "Processing";
                                break;

                            case "onboard":
                                JobFileName = _tokens.Resolve("Scheduler", "OnBoardDefinition", "No onboard definition defined in the settings file.  Please add a Tokens/Scheduler OnBoardDefinition");
                                message     = "OnBoarding";
                                break;

                            default:
                                throw new Exception(String.Format("{0} is not a valid action request.", action_requested));
                            }

                            // Kick off the definition
                            RunDefinition(JobKey, JobFileName, RawJobFileName, message);
                        }
                    }
                    fs.Close();
                }
                File.Delete(lockFilename);
            }
            catch (Exception ex)
            {
                lock (_lock)
                {
                    LocalLog.AddLine("Queue Error: " + ex.Message);
                }
                _AppLog.WriteEntry(ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);

                if (JobKey > 0)
                {
                    Dictionary <String, Object> sqlParameters = new Dictionary <string, object>();
                    sqlParameters.Add(":jobkey", JobKey);
                    sqlParameters.Add(":jobstatus", "Error");
                    sqlParameters.Add(":inprogress", false);
                    sqlParameters.Add(":scanrequested", false);
                    String message = String.Format("Recorded: {0:MMMM d, yyyy HH:mm:ss}, Message: {1} ", DateTime.Now, ex.Message);
                    if (message.Length > 99)
                    {
                        message = message.Substring(0, 99);
                    }
                    sqlParameters.Add(":statusdescription", message);
                    SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlUpdateInProgressStatus, sqlParameters);
                }
            }
        }