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)); }
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(); }