Ejemplo n.º 1
0
 private static void DeleteGeneratedFiles(JobProcessor processor)
 {
     m_Logger.Debug("Deleting generated files...");
     DeleteGeneratedFile(processor.PreviewPath, "Preview");
     DeleteGeneratedFile(processor.ThumbnailPath, "Thumbnail");
     m_Logger.Debug("Done deleting generated files");
 }
Ejemplo n.º 2
0
        private static void PerformCallback(APSQueuedJob job, JobProcessor processor)
        {
            m_Logger.Debug("Called PerformCallback()");

            if (String.IsNullOrEmpty(job.CallbackUrl))
            {
                AddLogEntry(job.QueuedJobId, "No callback URL specified, data not posted", LogEntryTarget.All);
            }
            else
            {
                string parsedMetadataXml = processor.MetadataXml.ToString().Replace("&", string.Empty);

                HttpPoster poster = new HttpPoster {
                    Url = job.CallbackUrl
                };
                poster.AddParameter("AssetId", processor.AssetId);
                poster.AddParameter("InputPath", processor.InputPath);
                poster.AddParameter("JobId", job.QueuedJobId);
                poster.AddParameter("MetadataXml", parsedMetadataXml);
                poster.AddParameter("AdditionalData", job.AdditionalData);
                poster.AddParameter("PluginRequested", processor.PluginUsed);
                poster.AddParameter("PluginUsed", processor.PluginUsed);
                poster.AddParameter("PreviewPath", processor.PreviewPath);
                poster.AddParameter("ThumbnailPath", processor.ThumbnailPath);
                poster.AddParameter("StatusId", job.QueuedJobStatusId);
                poster.AddParameter("Status", job.Status);
                poster.AddParameter("DateAdded", job.DateAdded);
                poster.AddParameter("DateProcessed", job.DateProcessed);

                foreach (var fdi in processor.FileDataItems)
                {
                    poster.AddParameter("FDI_" + fdi.Key, fdi.Value);
                }

                try
                {
                    string response = poster.Post();
                    AddLogEntry(job.QueuedJobId, string.Format("Posted data to callback url: {0}.  Response: {1}", poster.Url, response), LogEntryTarget.All);
                }
                catch (Exception ex)
                {
                    AddLogEntry(job.QueuedJobId, string.Format("Error posting data to callback url: {0}.  Error: {1}", poster.Url, ex.Message), LogEntryTarget.Database);

                    m_Logger.Error(string.Format("JobId: {0}, AssetId: {1} - Error posting data to callback url: {2}. Error: {3}", job.QueuedJobId, job.AssetId, poster.Url, ex.Message), ex);
                }
            }

            m_Logger.Debug("Exited PerformCallback()");
        }
Ejemplo n.º 3
0
        public static JobResult ProcessJob(Job job)
        {
            m_Logger.DebugFormat("Sending job for asset {0} for processing. No job id available.", job.AssetId);

            JobProcessor processor = new JobProcessor
            {
                JobId           = 0,
                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();

            return(new JobResult(job.AssetId, job.InputPath, processor.PreviewPath, processor.ThumbnailPath, job.AdditionalData, processor.MetadataXml.Root));
        }
Ejemplo n.º 4
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();
        }