Beispiel #1
0
        internal static IEnumerable <APSQueuedJob> GetPendingJobs(APSEntities db)
        {
            Debug.WriteLine("Called GetPendingJobs()");

            int jobStatusId = Convert.ToInt32(Status.NotStarted);

            // First get all of the queued jobs
            var list1 = (from job in db.APSQueuedJob
                         where (job.QueuedJobStatusId == jobStatusId)
                         select job).ToList();

            // Now sort them by the processing priority.  This is so that assets using plugins that are quick to process
            // such as image processing can be prioritized ahead of the others which take longer.
            var list2 = from job in list1
                        let ProcessingPriority = PluginManager.Instance.GetPluginInfo(job.PluginName, PathUtils.GetExtension(job.InputPath)).ProcessingPriority
                                                 orderby ProcessingPriority ascending, job.QueuedJobId ascending
            select job;

            List <APSQueuedJob> pendingJobs = list2.ToList();

            int jobCount = pendingJobs.Count();

            m_Logger.DebugFormat("Found {0} pending jobs", jobCount);

            return(pendingJobs);
        }
        /// <summary>
        /// Gets the service status
        /// </summary>
        public static ServiceStatus GetServiceStatus()
        {
            // Update the number of jobs in progress count
            Instance.NumberOfJobsInProgress = JobManager.Instance.NumberOfJobsInProgress;

            // Update the number of pending jobs count
            using (APSEntities db = new APSEntities(DBHelper.GetConnectionString()))
                Instance.NumberOfJobsInQueue = JobManager.GetPendingJobs(db).Count();

            return(Instance);
        }
Beispiel #3
0
 /// <summary>
 /// Adds a new message to the log
 /// </summary>
 /// <param name="jobId">Job ID</param>
 /// <param name="message">Message</param>
 public static void AddLogEntry(long jobId, string message)
 {
     using (APSEntities db = new APSEntities(DBHelper.GetConnectionString()))
     {
         APSLog log = new APSLog {
             JobId = jobId, Message = message, Date = DateTime.Now
         };
         db.AddToAPSLog(log);
         db.SaveChanges();
     }
 }
Beispiel #4
0
        /// <summary>
        /// Gets the most recent 200 debug log entries
        /// </summary>
        public static List <APSDebugLog> GetDebugLogEntries()
        {
            using (APSEntities db = new APSEntities(DBHelper.GetConnectionString()))
            {
                var entries = (from log in db.APSDebugLog
                               where log.Level.ToLower() == "debug"
                               orderby log.Date descending, log.APSDebugLogId descending
                               select log).Take(200);

                return(entries.ToList());
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets the most recent 200 log entries
        /// </summary>
        public static List <LogEntry> GetLogEntries()
        {
            using (APSEntities db = new APSEntities(DBHelper.GetConnectionString()))
            {
                var entries = (from log in db.APSLog
                               orderby log.Date descending, log.LogId descending
                               select new LogEntry {
                    JobId = log.JobId, Message = log.Message, Date = log.Date
                }).Take(200).ToList();

                return(entries);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets the most recent 200 entries for the specified asset id
        /// </summary>
        public static List <LogEntry> GetLogEntriesByAssetId(int assetId)
        {
            using (APSEntities db = new APSEntities(DBHelper.GetConnectionString()))
            {
                var entries = (from log in db.APSLog
                               join qj in db.APSQueuedJob on log.JobId equals qj.QueuedJobId
                               where qj.AssetId == assetId
                               orderby log.Date descending, log.LogId descending
                               select new LogEntry {
                    JobId = log.JobId, Message = log.Message, Date = log.Date
                }).Take(200).ToList();

                return(entries);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Adds a job to the processing queue
        /// </summary>
        /// <param name="job">The job to be added</param>
        /// <returns>Job ID</returns>
        public long AddJobToQueue(Job job)
        {
            // This method is not static as we want to
            // ensure that this class gets instantiated
            // so that the timer kicks off and processes jobs

            if (!JobIsValid(job))
            {
                return(0);
            }

            using (APSEntities db = new APSEntities(DBHelper.GetConnectionString()))
            {
                m_Logger.DebugFormat("Received job to add to queue.  Asset Id: {0}", job.AssetId);

                APSQueuedJob qj = new APSQueuedJob
                {
                    AssetId         = job.AssetId,
                    InputPath       = job.InputPath,
                    WatermarkPath   = job.WatermarkPath ?? string.Empty,
                    PluginName      = job.PluginName ?? string.Empty,
                    CreateThumbnail = job.CreateThumbnail,
                    CreatePreview   = job.CreatePreview,
                    OverrideWidth   = job.OverrideWidth,
                    OverrideHeight  = job.OverrideHeight,
                    DateAdded       = DateTime.Now,
                    DateProcessed   = null,
                    Status          = Status.NotStarted,
                    Message         = "Added",
                    CallbackUrl     = job.CallbackUrl ?? string.Empty,
                    AdditionalData  = job.AdditionalData
                };

                db.AddToAPSQueuedJob(qj);
                db.SaveChanges();

                string message = string.Format("Job for asset with id '{0}' added to queue with Id '{1}'", qj.AssetId, qj.QueuedJobId);
                AddLogEntry(qj.QueuedJobId, message, LogEntryTarget.All);

                return(qj.QueuedJobId);
            }
        }
        private void CheckDatabaseConnectivity()
        {
            try
            {
                int statusId = Convert.ToInt32(Status.NotStarted);

                using (APSEntities db = new APSEntities(DBHelper.GetConnectionString()))
                {
                    int count = (from qj in db.APSQueuedJob
                                 where qj.QueuedJobStatusId == statusId
                                 select qj).Count();

                    m_Logger.DebugFormat("Database connectivity verified (job count: {0})", count);
                }
            }
            catch (Exception ex)
            {
                m_Logger.Error(string.Format("Error with local database connectivity: {0}", ex.Message), ex);
                m_ErrorCount++;
            }
        }
Beispiel #9
0
        public void ProcessQueuedJobs()
        {
            Console.WriteLine("Processing queued jobs");

            if (NumberOfJobsInProgress >= MaxNumberOfConcurrentJobs)
            {
                Debug.Write(string.Format("Already processing maximum number of concurrent jobs available - in progress: {0}, max: {1}", NumberOfJobsInProgress, MaxNumberOfConcurrentJobs));
                Console.WriteLine("Already processing maximum number of concurrent jobs available");
                return;
            }

            try
            {
                using (APSEntities db = new APSEntities(DBHelper.GetConnectionString()))
                {
                    Console.WriteLine("Checking queue...");

                    ServiceStatus.Instance.QueueLastChecked = DateTime.Now;

                    while (GetPendingJobs(db).Count() > 0)
                    {
                        Console.WriteLine("Found jobs");

                        var jobs = GetPendingJobs(db);

                        m_Logger.DebugFormat("Found {0} pending jobs needing to be processed", jobs.Count());

                        APSQueuedJob job = jobs.FirstOrDefault();

                        if (job == null)
                        {
                            break;
                        }

                        AddLogEntry(job.QueuedJobId, string.Format("Processing job: {0}", job.QueuedJobId), LogEntryTarget.All);

                        try
                        {
                            NumberOfJobsInProgress++;

                            job.Message = "Processing...";
                            job.Status  = Status.Processing;
                            db.SaveChanges();

                            m_Logger.Debug("Sending to job processor");

                            JobProcessor processor = new JobProcessor
                            {
                                JobId           = job.QueuedJobId,
                                AssetId         = job.AssetId,
                                InputPath       = job.InputPath,
                                WatermarkPath   = job.WatermarkPath,
                                PluginName      = job.PluginName,
                                CreatePreview   = job.CreatePreview,
                                CreateThumbnail = job.CreateThumbnail,
                                OverrideHeight  = job.OverrideHeight,
                                OverrideWidth   = job.OverrideWidth
                            };
                            processor.Go();

                            AddLogEntry(job.QueuedJobId, "Done processing job", LogEntryTarget.All);

                            job.DateProcessed = DateTime.Now;

                            if (processor.HasErrors)
                            {
                                job.Message = "Completed with errors. Check log for details";
                                job.Status  = Status.CompletedWithErrors;
                            }
                            else
                            {
                                job.Message = "Processing completed successfully";
                                job.Status  = Status.CompletedSuccessfully;
                            }

                            PerformCallback(job, processor);

                            if (DeleteGeneratedFilesAfterCallback)
                            {
                                DeleteGeneratedFiles(processor);
                            }
                            else
                            {
                                m_Logger.Debug("Generated files not deleted as DeleteGeneratedFilesAfterCallback setting is false");
                            }
                        }
                        catch (Exception ex)
                        {
                            AddLogEntry(job.QueuedJobId, "Processing completed with errors: " + ex.Message, LogEntryTarget.Database);

                            m_Logger.Error("Error processing job: " + ex.Message, ex);

                            job.Message = "Processing completed with errors: " + ex.Message;
                            job.Status  = Status.CompletedWithErrors;
                        }
                        finally
                        {
                            NumberOfJobsInProgress--;
                            ServiceStatus.Instance.NumberOfJobsProcessed++;
                        }

                        db.SaveChanges();

                        Console.WriteLine("Finished processing job: {0}", job.QueuedJobId);
                    }

                    Console.WriteLine("No more pending jobs to be processed");
                }
            }
            catch (Exception ex)
            {
                m_Logger.Error(string.Format("ProcessQueuedJobs: Error processing queued jobs: {0}", ex.Message), ex);
            }

            Console.WriteLine("Number of other jobs currently in progress: {0}", NumberOfJobsInProgress);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("...");
            Console.WriteLine();
            Console.WriteLine();
        }