Example #1
0
        public DebugWindow(IApplication application, IJobProcessor jobProcessor)
        {
            _application = application;
            JobProcessor = jobProcessor;

            InitializeComponent();
        }
Example #2
0
 internal Scheduler(string fileName, ITwitterContextList contextList, ITwitterConfiguration twitterConfig,
                    IJobProcessor testProcessor, int sleepTime = 1000)
     : this(fileName, contextList, twitterConfig)
 {
     JobProcessors.Add(SchedulerJobType.Test, testProcessor);
     SleepTime = sleepTime;
 }
 public InfiniteRetryProcessor(
     IJobProcessor inner,
     ILoggerFactory loggerFactory)
 {
     _inner  = inner;
     _logger = loggerFactory.CreateLogger <InfiniteRetryProcessor>();
 }
Example #4
0
 public StreamHub(IJobProvider jobProvider,
                  IJobProcessor jobProcessor,
                  IJobBufferHandler buffer)
 {
     this.jobProvider  = jobProvider;
     this.jobProcessor = jobProcessor;
     this.buffer       = buffer;
 }
Example #5
0
        public static CMDPipeJobProcessor NewCMDPipeJobProcessor(IJobProcessor stdout, IJobProcessor stdin)
        {
            var pipe = new CMDPipeJobProcessor();

            pipe.SetStdOut(stdout as CommandlineJobProcessor);
            pipe.SetStdIn(stdin as CommandlineJobProcessor);

            return(pipe);
        }
 public VariableApiController(UserManager <ApplicationUser> userManager,
                              IOptions <ReportContentOptions> reportOptions,
                              IJobProcessor processor,
                              IDataRegistry registry)
 {
     _userManager   = userManager;
     _reportOptions = reportOptions.Value;
     _processor     = processor;
     _registry      = registry;
 }
Example #7
0
        public Shell(IApplication application, IJobProcessor jobProcessor, IWindowsAggregateService windowsAggregateService)
        {
            _application  = application;
            _jobProcessor = jobProcessor;
            _taskbarIcon  = windowsAggregateService.TaskbarIcon;
            _aeroSnap     = windowsAggregateService.AeroSnap;

            InitializeJobProcessor();
            InitializeTaskbarIcon();
        }
Example #8
0
        private void SetupJobs(IEnumerable <IJob> jobs)
        {
            //_completedJobs = new Dictionary<int, IJob>();
            _jobs          = new List <IJob>(jobs);
            _availableJobs = new JobProcessorList(_jobPriorityFunction);

            foreach (var job in _jobs.Where(x => x.Predecessors.Count == 0).OrderBy(x => x.Duration))
            {
                _availableJobs.Enqueue(job);
            }
        }
Example #9
0
        public VSPipeInfo(string vsScriptPath)
        {
            VideoInfoJob j = new VideoInfoJob(vsScriptPath);

            IJobProcessor processor = VSPipeProcessor.NewVSPipeProcessor(j);

            processor.start();

            videoInfo = (processor as VSPipeProcessor).VideoInfo;

            UpdateVideoInfo();
        }
Example #10
0
        /// <summary>
        /// checks all available video encoders to see if one supports the desired video codec with the desired
        /// output type
        /// </summary>
        /// <param name="videoCodec">the desired video codec</param>
        /// <param name="outputType">the desired video output</param>
        /// <returns>true if the codec/output type combo can be fullfilled, false if not</returns>
        public bool IsSupported(TEncoderType codec, TType outputType)
        {
            IJobProcessor encoder = GetEncoder(new MeGUISettings(), codec, outputType);

            if (encoder != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #11
0
 private IJobProcessor getProcessor(Job job)
 {
     foreach (JobProcessorFactory f in mainForm.PackageSystem.JobProcessors.Values)
     {
         IJobProcessor p = f.Factory(mainForm, job);
         if (p != null)
         {
             return(p);
         }
     }
     log.Error("No processor found");
     return(null);
 }
Example #12
0
        public IJobProcessor CreateProcessor(MainForm info, Job job)
        {
            Dictionary <JobProcessorFactory, IJobProcessor> processors = new Dictionary <JobProcessorFactory, IJobProcessor>();

            foreach (JobProcessorFactory factory in this.Values)
            {
                IJobProcessor processor = factory.Factory(info, job);
                if (processor != null)
                {
                    processors.Add(factory, processor);
                }
            }
            return(null);
        }
 public DefaultScheduler(
     TStorageKey schedulerId,
     ISchedulerMetadata schedulerMetadata,
     ISchedulerMetadataStore <TStorageKey> schedulerMetadataStore,
     IClusterStateMonitor <TStorageKey> clusterStateMonitor,
     IJobProcessor <TStorageKey> jobProcessor,
     ILogger <DefaultScheduler <TStorageKey> > logger)
 {
     this.schedulerId            = schedulerId;
     this.metadata               = schedulerMetadata;
     this.schedulerMetadataStore = schedulerMetadataStore;
     this.clusterStateMonitor    = clusterStateMonitor;
     this.jobProcessor           = jobProcessor;
     this.logger = logger;
 }
Example #14
0
 private IJobProcessor getProcessor(Job job)
 {
     mainForm.addToLog("Looking for job processor for job...\r\n");
     foreach (JobProcessorFactory f in mainForm.PackageSystem.JobProcessors.Values)
     {
         IJobProcessor p = f.Factory(mainForm, job);
         if (p != null)
         {
             mainForm.addToLog("Processor found!\r\n");
             return(p);
         }
     }
     mainForm.addToLog("No processor found!\r\n");
     return(null);
 }
Example #15
0
 public HomeController(
     ApplicationDbContext context,
     RoleManager <IdentityRole> roleMan,
     UserManager <ApplicationUser> userManager,
     IJobService jobService,
     INotificationService notificationService,
     IJobProcessor processor)
 {
     _context             = context;
     _roleManager         = roleMan;
     _userManager         = userManager;
     _jobService          = jobService;
     _notificationService = notificationService;
     _processor           = processor;
 }
        public JobProcessorTests()
        {
            var services = new ServiceCollection();

            services.AddSingleton <IJobStorage>(new MemoryJobStorage(new NullLogger <MemoryJobStorage>(), null));
            services.AddSingleton <IJobExecutor>(x => new JobExecutor(x.GetRequiredService <IServiceScopeFactory>(),
                                                                      new NullLogger <JobExecutor>(), x.GetRequiredService <IJobStorage>()));
            services.AddSingleton <IJobProcessor>(x => new SingleThreadJobProcessor(x.GetRequiredService <IJobStorage>(),
                                                                                    x.GetRequiredService <IJobExecutor>(), new NullLogger <SingleThreadJobProcessor>()));
            services.AddTransient <TestJob>();

            var provider = services.BuildServiceProvider();

            _jobStorage   = provider.GetRequiredService <IJobStorage>();
            _jobProcessor = provider.GetRequiredService <IJobProcessor>();
        }
Example #17
0
        public static IJobProcessor CreateProcessor(ProcessorConfig config, IServiceProvider provider)
        {
            IJobProcessor res = null;

            if (config.DataConsumer == null)
            {
                res = new PassiveJobProcessor(config.Id, provider);
                ((PassiveJobProcessor)res).Initialize(config);
            }
            else
            {
                res = new ActiveJobProcessor(config.Id, provider);
                ((ActiveJobProcessor)res).Initialize(config);
            }
            return(res);
        }
Example #18
0
        public IJobProcessor CreateProcessor(MainForm info, Job job)
        {
            Dictionary <JobProcessorFactory, IJobProcessor> processors = new Dictionary <JobProcessorFactory, IJobProcessor>();

            foreach (JobProcessorFactory factory in this.Values)
            {
                IJobProcessor processor = factory.Factory(info, job);
                if (processor != null)
                {
                    processors.Add(factory, processor);
                }
            }
            return(null);

#warning must add a job processor comparer
//            return info.JobProcessorComparer.FindBestProcessor(processors);
        }
Example #19
0
        /// <summary>
        /// gets an encoder for the given codec and output type
        /// </summary>
        /// <param name="videoCodec">the desired video codec</param>
        /// <param name="outputType">the desired output type</param>
        /// <returns>the encoder found or null if no encoder was found</returns>
        public IJobProcessor GetEncoder(MeGUISettings settings, TEncoderType codec, TType outputType)
        {
            IJobProcessor encoder = null;

            foreach (IEncoding <TCodec, TType, TEncoderType> encodingInterface in this.registeredEncoders)
            {
                if (!encodingInterface.GetSupportedEncoderTypes().Contains(codec))
                {
                    continue;
                }
                if (!encodingInterface.GetSupportedOutputTypes(codec).Contains(outputType))
                {
                    continue;
                }
                encoder = encodingInterface.GetEncoder(codec, outputType, settings);
            }
            return(encoder);
        }
Example #20
0
        public IJobProcessor GetProcessor(string id, bool newInstance = false)
        {
            IJobProcessor res = null;

            if (newInstance)
            {
                var p = _processorConfigs?.Where(i => i.Id == id).FirstOrDefault();

                if (p != null)
                {
                    var processor = JobProcessorFactory.CreateProcessor(p, _provider);
                    res = processor;
                }
            }
            else
            {
                res = Processors?.Where(p => p.Id == id).FirstOrDefault();
            }

            return(res);
        }
Example #21
0
 public JobService(ApplicationDbContext context,
                   IJobProcessor processor,
                   INotificationService notifyService,
                   IEmailSender emailSender,
                   IReportGenerator reportGenerator,
                   IOutputPersistence outputPersistence,
                   UserManager <ApplicationUser> userManager,
                   IOptions <EcosetAppOptions> appOptions,
                   IDataRegistry registry,
                   ILogger <JobService> logger)
 {
     _context           = context;
     _processor         = processor;
     _notifyService     = notifyService;
     _emailSender       = emailSender;
     _outputPersistence = outputPersistence;
     _reportGenerator   = reportGenerator;
     _userManager       = userManager;
     _appOptions        = appOptions.Value;
     _registry          = registry;
     _logger            = logger;
 }
        public ProcessorGeneralTests()
        {
            MockLogger    = new Mock <ILogger <HttpPushOutgoingQueueProcessor> >();
            MockMessageDa = new Mock <IMessageLogDa>();
            NebulaContext = new NebulaContext();
            NebulaContext.RegisterJobQueue(typeof(MockDelayedQueue), QueueType.Delayed);
            Interlocked.Increment(ref _portNumber);
            var baseAddress = $"http://localhost:{_portNumber}";

            Parameters = new HttpPushOutgoingQueueParameters
            {
                TargetUrl = $"{baseAddress}/endpoint"
            };
            StubHttp         = HttpMockRepository.At(baseAddress);
            JobConfiguration = new JobConfigurationData
            {
                MaxBatchSize = 1,
                MaxConcurrentBatchesPerWorker = 5,
                IdleSecondsToCompletion       = 30,
                MaxBlockedSecondsPerCycle     = 60,
                MaxTargetQueueLength          = 100000,
                QueueTypeName = QueueType.Redis,
                Parameters    = JsonConvert.SerializeObject(Parameters)
            };

            JobData = new JobData
            {
                JobId         = "test_job_id",
                Configuration = JobConfiguration,
                TenantId      = TenantId
            };
            Options = Microsoft.Extensions.Options.Options.Create(
                new RetryConfiguration {
                Count = 0, Interval = 0
            });
            Processor = new HttpPushOutgoingQueueProcessor(MockLogger.Object, MockMessageDa.Object, Options);
            NebulaContext.RegisterJobProcessor(Processor, typeof(HttpPushOutgoingQueueStep));
        }
Example #23
0
        public virtual bool setup(Job job, out string error)
        {
            if (!(job is VideoJob))
            {
                throw new Exception("Setup was called on a non-video job");
            }
            VideoJob vJob = (VideoJob)job;

            if (vJob.Settings is x264Settings)
            {
                encoder = new x264Encoder(settings.X264Path);
            }
            else if (vJob.Settings is xvidSettings)
            {
                encoder = new XviDEncoder(settings.XviDEncrawPath);
            }
            else
            {
                encoder = new mencoderEncoder(settings.MencoderPath);
            }
            error = null;
            return(encoder.setup(job, out error));
        }
Example #24
0
        /// <summary>
        /// starts the job provided as parameters
        /// </summary>
        /// <param name="job">the Job object containing all the parameters</param>
        /// <returns>success / failure indicator</returns>
        private bool startEncoding(TaggedJob job)
        {
            try
            {
                log = mainForm.Log.Info(string.Format("Log for {0} ({1}, {2} -> {3})", job.Name, job.Job.EncodingMode, job.InputFileName, job.OutputFileName));
                log.LogEvent("Started handling job");
                log.Expand();

                status = JobWorkerStatus.Running;
                //Check to see if output file already exists before encoding.
                if (File.Exists(job.Job.Output) && !mainForm.DialogManager.overwriteJobOutput(job.Job.Output))
                {
                    throw new JobStartException("File exists and the user doesn't want to overwrite", ExceptionType.UserSkip);
                }

                // Get IJobProcessor
                currentProcessor = getProcessor(job.Job);
                if (currentProcessor == null)
                {
                    throw new JobStartException("No processor could be found", ExceptionType.Error);
                }


                // Preprocess
                preprocessJob(job.Job);

                // Setup
                try
                {
                    currentProcessor.setup(job.Job, new StatusUpdate(job.Name), log);
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("Calling setup of processor failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                // Do JobControl setup
                currentProcessor.StatusUpdate += new JobProcessingStatusUpdateCallback(UpdateGUIStatus);

                // Progress window
                pw.setPriority(mainForm.Settings.DefaultPriority);
                if (mainForm.Settings.OpenProgressWindow && mainForm.Visible)
                {
                    this.ShowProcessWindow();
                }

                job.Status  = JobStatus.PROCESSING;
                job.Start   = DateTime.Now;
                status      = JobWorkerStatus.Running;
                pauseStatus = PauseState.Encoding;
                currentJob  = job;

                // Start
                try
                {
                    currentProcessor.start();
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("starting encoder failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                log.LogEvent("Encoding started");
                refreshAll();
                return(true);
            }
            catch (JobStartException e)
            {
                mainForm.Log.LogValue("Error starting job", e);
                if (e.type == ExceptionType.Error)
                {
                    job.Status = JobStatus.ERROR;
                }
                else // ExceptionType.UserSkip
                {
                    job.Status = JobStatus.SKIP;
                }
                currentProcessor = null;
                currentJob       = null;
                status           = JobWorkerStatus.Idle;
                pauseStatus      = PauseState.NotEncoding;
                refreshAll();
                return(false);
            }
        }
Example #25
0
        /// <summary>
        /// starts the job provided as parameters
        /// </summary>
        /// <param name="job">the Job object containing all the parameters</param>
        /// <returns>success / failure indicator</returns>
        private bool startEncoding(Job job)
        {
            Debug.Assert(status == JobWorkerStatus.Idle);

            try
            {
                //Check to see if output file already exists before encoding.
                if (File.Exists(job.Output) && !mainForm.DialogManager.overwriteJobOutput(job.Output))
                    throw new JobStartException("File exists and the user doesn't want to overwrite", ExceptionType.UserSkip);

                // Get IJobProcessor
                currentProcessor = getProcessor(job);
                if (currentProcessor == null)
                    throw new JobStartException("No processor could be found", ExceptionType.Error);

                addToLog("\r\n\r\n------------------------------------------------------\r\n\r\n");
                addToLog("Starting job " + job.Name + " at " + DateTime.Now.ToLongTimeString() + "\r\n");

                // Preprocess
                preprocessJob(job);

                // Setup
                try
                {
                    currentProcessor.setup(job);
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("Calling setup of processor failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                // Do JobControl setup
                addToLog("encoder commandline:\r\n" + job.Commandline + "\r\n");
                currentProcessor.StatusUpdate += new JobProcessingStatusUpdateCallback(UpdateGUIStatus);

                // Progress window
                pw = new ProgressWindow(job.JobType);
                pw.WindowClosed += new WindowClosedCallback(pw_WindowClosed);
                pw.Abort += new AbortCallback(pw_Abort);
                pw.setPriority(job.Priority);
                pw.PriorityChanged += new PriorityChangedCallback(pw_PriorityChanged);
                if (mainForm.Settings.OpenProgressWindow && mainForm.Visible)
                    pw.Show();

                job.Status = JobStatus.PROCESSING;
                job.Start = DateTime.Now;
                status = JobWorkerStatus.Running;
                pauseStatus = PauseState.Encoding;
                currentJob = job;

                // Start
                try
                {
                    currentProcessor.start();
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("starting encoder failed with error '" + e.Message +"'", ExceptionType.Error);
                }

                addToLog("successfully started encoding\r\n");

                refreshAll();
                return true;
            }
            catch (JobStartException e)
            {
                addToLog("Job not started. Reason: " + e.Message + "\r\n");
                if (e.type == ExceptionType.Error)
                    job.Status = JobStatus.ERROR;
                else // ExceptionType.UserSkip
                    job.Status = JobStatus.SKIP;
                currentProcessor = null;
                currentJob = null;
                status = JobWorkerStatus.Idle;
                pauseStatus = PauseState.NotEncoding;
                refreshAll();
                return false;
            }
        }
Example #26
0
        /// <summary>
        /// updates the actual GUI with the status information received as parameter
        /// If the StatusUpdate indicates that the job has ended, the Progress window is closed
        /// and the logging messages from the StatusUpdate object are added to the log tab
        /// if the job mentioned in the statusupdate has a next job name defined, the job is looked
        /// up and processing of that job starts - this applies even in queue encoding mode
        /// the linked jobs will always be encoded first, regardless of their position in the queue
        /// If we're in queue encoding mode, the next nob in the queue is also started
        /// </summary>
        /// <param name="su">StatusUpdate object containing the current encoder stats</param>
        private void UpdateGUIStatus(StatusUpdate su)
        {
            if (su.IsComplete)
            {
                // so we don't lock up the GUI, we start a new thread
                Thread t = new Thread(new ThreadStart(delegate
                {
                    TaggedJob job = mainForm.Jobs.ByName(su.JobName);

                    copyInfoIntoJob(job, su);
                    progress = 0;
                    HideProcessWindow();

                    // Postprocessing
                    bool jobFailed = (job.Status != JobStatus.PROCESSING);
                    if (!jobFailed)
                    {
                        postprocessJob(job.Job);
                        job.Status = JobStatus.DONE;
                    }

                    currentProcessor = null;
                    currentJob       = null;

                    // Logging
                    log.LogEvent("Job completed");
                    log.Collapse();

                    if (!jobFailed && mainForm.Settings.DeleteCompletedJobs)
                    {
                        mainForm.Jobs.RemoveCompletedJob(job);
                    }
                    else
                    {
                        mainForm.Jobs.saveJob(job, mainForm.MeGUIPath);     //AAA: save state more often
                    }
                    if (shutdownWorkerIfJobsCompleted())
                    {
                    }
                    else if (job.Status == JobStatus.ABORTED)
                    {
                        log.LogEvent("Current job was aborted");
                        status = JobWorkerStatus.Idle;
                    }
                    else if (status == JobWorkerStatus.Stopping)
                    {
                        log.LogEvent("Queue mode stopped");
                        status = JobWorkerStatus.Idle;
                    }
                    else
                    {
                        switch (startNextJobInQueue())
                        {
                        case JobStartInfo.JOB_STARTED:
                            break;

                        case JobStartInfo.COULDNT_START:
                            status = JobWorkerStatus.Idle;
                            break;

                        case JobStartInfo.NO_JOBS_WAITING:
                            status = JobWorkerStatus.Idle;
                            new Thread(delegate()
                            {
                                WorkerFinishedJobs(this, EventArgs.Empty);
                            }).Start();
                            break;
                        }
                    }

                    refreshAll();
                }));
                t.IsBackground = true;
                t.Start();
            }
            else // job is not complete yet
            {
                try
                {
                    if (pw.IsHandleCreated && pw.Visible) // the window is there, send the update to the window
                    {
                        pw.BeginInvoke(new UpdateStatusCallback(pw.UpdateStatus), su);
                    }
                }
                catch (Exception e)
                {
                    mainForm.Log.LogValue("Error trying to update status while a job is running", e, ImageType.Warning);
                }

                progress = su.PercentageDoneExact ?? 0;
                updateProgress();
            }
        }
Example #27
0
        private void StartProcessing()
        {
            if (this.job == null)
            {
                return;
            }

            if (this.job.IsComplete)
            {
                this.job.Reset();
            }

            this.job.IsIdle = false;

            this.processor = this.jobProcessorFactory.CreateJobProcessor(this.HandleProcessingFinished);

            this.processor.RunAsync(this.job);
        }
Example #28
0
        /// <summary>
        /// updates the actual GUI with the status information received as parameter
        /// If the StatusUpdate indicates that the job has ended, the Progress window is closed
        /// and the logging messages from the StatusUpdate object are added to the log tab
        /// if the job mentioned in the statusupdate has a next job name defined, the job is looked
        /// up and processing of that job starts - this applies even in queue encoding mode
        /// the linked jobs will always be encoded first, regardless of their position in the queue
        /// If we're in queue encoding mode, the next nob in the queue is also started
        /// </summary>
        /// <param name="su">StatusUpdate object containing the current encoder stats</param>
        private void UpdateGUIStatus(StatusUpdate su)
        {
            if (su.IsComplete)
            {
                // so we don't lock up the GUI, we start a new thread
                new Thread(new ThreadStart(delegate
                {
                    Job job = mainForm.Jobs.ByName(su.JobName);

                    copyInfoIntoJob(job, su);
                    progress = 0;
                    ensureProgressWindowClosed();
                    currentProcessor = null;
                    currentJob = null;

                    // Logging
                    addToLog("Processing ended at " + DateTime.Now.ToLongTimeString() + "\r\n");
                    addToLog("----------------------" +
                        "\r\n\r\nLog for job " + su.JobName + "\r\n\r\n" + su.Log +
                        "\r\n----------------------\r\n");

                    // Postprocessing
                    bool jobCompletedSuccessfully = (job.Status == JobStatus.DONE);
                    if (jobCompletedSuccessfully)
                        postprocessJob(job);

                    if (jobCompletedSuccessfully && mainForm.Settings.DeleteCompletedJobs)
                        mainForm.Jobs.removeCompletedJob(job);

                    addToLog("End of log for " + job.Name + "\r\n" +
                        "-------------------------------------------------------\r\n\r\n");

                    if (job.Status == JobStatus.ABORTED)
                    {
                        addToLog("The current job was aborted. Stopping queue mode\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else if (status == JobWorkerStatus.Stopping)
                    {
                        addToLog("Told to stop. Stopping queue mode.\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else
                        startNextJobInQueue();

                    refreshAll();
                })).Start();
            }
            else // job is not complete yet
            {
                try
                {
                    if (pw.IsHandleCreated) // the window is there, send the update to the window
                    {
                        pw.Invoke(new UpdateStatusCallback(pw.UpdateStatus), new object[] { su });
                    }
                }
                catch (Exception e)
                {
                    mainForm.addToLog("Exception when trying to update status while a job is running. Text: " + e.Message + " stacktrace: " + e.StackTrace);
                }

                progress = su.PercentageDone;
                /*
                string percentage = (su.PercentageDoneExact ?? 0M).ToString("##.##");
                if (percentage.IndexOf(".") != -1 && percentage.Substring(percentage.IndexOf(".")).Length == 1)
                    percentage += "0";
                mainForm.TitleText = "MeGUI " + su.JobName + " " + percentage + "% ";
                if (mainForm.Settings.AfterEncoding == AfterEncoding.Shutdown)
                    mainForm.TitleText += "- SHUTDOWN after encode";
                this.jobProgress.Value = su.PercentageDone;*/
            }
        }
Example #29
0
 public void Initialize(IJobProcessor processor)
 {
     this.restService = new RestService(processor);
     var baseUrl = string.Format("http://localhost:{0}/", listenPort);
     this.serviceHost = new WebServiceHost(restService, new Uri(baseUrl));
 }
Example #30
0
 /// <summary>
 /// Creates an instance of the main worker service
 /// </summary>
 /// <param name="autoScaleProducerClient">Auto scale producer service client</param>
 /// <param name="jobProcessor">Job processor for handling the job if needed.</param>
 public HostService(IAutoScaleProducerClient autoScaleProducerClient, IJobProcessor jobProcessor)
 {
     this.autoScaleProducerClient = autoScaleProducerClient ?? throw new ArgumentNullException(nameof(autoScaleProducerClient));
     this.jobProcessor            = jobProcessor ?? throw new ArgumentNullException(nameof(jobProcessor));
     this.processCount            = 1; // 1 because of the host process
 }
 public void ProcessAllJobs(List<Job> jobs, IJobProcessor processor)
 {
     foreach (var job in jobs)
     {
         processor.ProcessJob(job);
     }
 }
Example #32
0
 public RestService(IJobProcessor processor)
 {
     this.processor = processor;
 }
Example #33
0
        private async Task RunProgramAsync(string logPath, int numberOfParsers, CancellationTokenSource ctSource)
        {
            WriteLog(LogEventLevel.Information, $"Starting to process EQ Log file: {logPath}");
            _eqJob = CreateJobProcessor(numberOfParsers);
            _eqJob.CancelSource = ctSource;

            // Get started waiting for user input
            // When the user quits, then cancel our CTS (which will cause our JobTask to be cancelled)
            var consoleTask = GetConsoleUserInputAsync(ctSource.Token);
            var ctComplete  = consoleTask.ContinueWith(_ => ctSource.Cancel(), TaskContinuationOptions.OnlyOnRanToCompletion);
            // var ctContinue = consoleTask.ContinueWith(_ => { }); // Empty task to await upon

            // Start the JobProcessor, which will read from the log file continuously, parse the lines and add them to the EQBattle
            // When it's done, show the summary
            var jobTask = _eqJob.StartProcessingJobAsync(logPath, _eqBattle);
            var jtError = jobTask.ContinueWith(_ => Log.Error(_.Exception, $"JobTask Error"), TaskContinuationOptions.OnlyOnFaulted);

            // Either the log file wasn't found, or we finished reading the log file. It either case,
            // we need to cancel the 'consoleTask' so we don't wait for the user when we know we're done.
            var jtNotCancelled = jobTask.ContinueWith(_ => ctSource.Cancel(), TaskContinuationOptions.NotOnCanceled);

            // When everything completed successfully (which doesn't reall happen) or cancelled (which is the normal path), show the final status
            var jtComplete = jobTask.ContinueWith(_ => ShowBattleSummary(), TaskContinuationOptions.NotOnFaulted);

            ConcurrentBag <Task> tasksToWaitFor = new ConcurrentBag <Task>();

            try
            {
                // Wait for everything to finish.
                // await Task.WhenAll(ctComplete, ctContinue, jtError, jtNotCancelled, jtComplete);
                // await ctContinue;
                // ctSource.CancelAfter(7*1000);

                await Task.WhenAll(consoleTask, jobTask);

                tasksToWaitFor.Add(jtNotCancelled);
                tasksToWaitFor.Add(jtComplete);
            }
            // catch (TaskCanceledException)
            // {
            //     WriteMessage($"{ex.GetType().Name} - {ex.Message}");
            // }
            catch (OperationCanceledException)
            {
                Log.Information("Program OperationCanceledException");

                if (jobTask.IsCanceled)
                {
                    tasksToWaitFor.Add(jtComplete);
                }
            }
            catch (Exception ex)
            {
                Log.Warning(ex, $"Program Exception");
                WriteMessage($"ERROR: {ex.Message}");

                if (jobTask.IsFaulted)
                {
                    tasksToWaitFor.Add(jtNotCancelled);
                    tasksToWaitFor.Add(jtError);
                }
            }
            finally
            {
                Log.Verbose("Program Finally Block");
                // await Task.WhenAny(jtNotCancelled, jtComplete);
                // await Task.WhenAny(jtError, jtComplete);
                // await jtComplete;
                await Task.WhenAll(tasksToWaitFor);

                DumpTaskInfo(consoleTask, "consoleTask");
                // DumpTaskInfo(ctComplete, "ctComplete");
                // DumpTaskInfo(ctContinue, "ctContinue");
                DumpTaskInfo(jobTask, "jobTask");
                DumpTaskInfo(jtError, "jtError");
                DumpTaskInfo(jtNotCancelled, "jtNotCancelled");
                DumpTaskInfo(jtComplete, "jtComplete");
            }
        }
Example #34
0
        private void SetupJobs(IEnumerable<IJob> jobs)
        {
            //_completedJobs = new Dictionary<int, IJob>();
            _jobs = new List<IJob>(jobs);
            _availableJobs = new JobProcessorList(_jobPriorityFunction);

            foreach (var job in _jobs.Where(x => x.Predecessors.Count == 0).OrderBy(x => x.Duration))
            {
                _availableJobs.Enqueue(job);
            }
        }
Example #35
0
        /// <summary>
        /// starts the job provided as parameters
        /// </summary>
        /// <param name="job">the Job object containing all the parameters</param>
        /// <returns>success / failure indicator</returns>
        private bool startEncoding(TaggedJob job)
        {
            try
            {
                status = JobWorkerStatus.Running;
                //Check to see if output file already exists before encoding.
                if (File.Exists(job.Job.Output) && !mainForm.DialogManager.overwriteJobOutput(job.Job.Output))
                {
                    throw new JobStartException("File exists and the user doesn't want to overwrite", ExceptionType.UserSkip);
                }

                // Get IJobProcessor
                currentProcessor = getProcessor(job.Job);
                if (currentProcessor == null)
                {
                    throw new JobStartException("No processor could be found", ExceptionType.Error);
                }

                addToLog("\r\n\r\n------------------------------------------------------\r\n\r\n");
                addToLog("Starting job " + job.Name + " at " + DateTime.Now.ToLongTimeString() + "\r\n");

                // Preprocess
                preprocessJob(job.Job);

                // Setup
                try
                {
                    currentProcessor.setup(job.Job, new StatusUpdate(job.Name));
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("Calling setup of processor failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                // Do JobControl setup
                //addToLog("encoder commandline:\r\n" + job.Commandline + "\r\n");
                currentProcessor.StatusUpdate += new JobProcessingStatusUpdateCallback(UpdateGUIStatus);

                // Progress window
                pw.setPriority(mainForm.Settings.DefaultPriority);
                if (mainForm.Settings.OpenProgressWindow && mainForm.Visible)
                {
                    this.ShowProcessWindow();
                }

                job.Status  = JobStatus.PROCESSING;
                job.Start   = DateTime.Now;
                status      = JobWorkerStatus.Running;
                pauseStatus = PauseState.Encoding;
                currentJob  = job;

                // Start
                try
                {
                    currentProcessor.start();
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("starting encoder failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                addToLog("successfully started encoding\r\n");
                refreshAll();
                return(true);
            }
            catch (JobStartException e)
            {
                addToLog("Job not started. Reason: " + e.Message + "\r\n");
                if (e.type == ExceptionType.Error)
                {
                    job.Status = JobStatus.ERROR;
                }
                else // ExceptionType.UserSkip
                {
                    job.Status = JobStatus.SKIP;
                }
                currentProcessor = null;
                currentJob       = null;
                status           = JobWorkerStatus.Idle;
                pauseStatus      = PauseState.NotEncoding;
                refreshAll();
                return(false);
            }
        }
Example #36
0
        /// <summary>
        /// updates the actual GUI with the status information received as parameter
        /// If the StatusUpdate indicates that the job has ended, the Progress window is closed
        /// and the logging messages from the StatusUpdate object are added to the log tab
        /// if the job mentioned in the statusupdate has a next job name defined, the job is looked
        /// up and processing of that job starts - this applies even in queue encoding mode
        /// the linked jobs will always be encoded first, regardless of their position in the queue
        /// If we're in queue encoding mode, the next nob in the queue is also started
        /// </summary>
        /// <param name="su">StatusUpdate object containing the current encoder stats</param>
        private void UpdateGUIStatus(StatusUpdate su)
        {
            if (su.IsComplete)
            {
                // so we don't lock up the GUI, we start a new thread
                Thread t = new Thread(new ThreadStart(delegate
                {
                    TaggedJob job = mainForm.Jobs.ByName(su.JobName);

                    copyInfoIntoJob(job, su);
                    progress = 0;
                    //ensureProgressWindowClosed();
                    HideProcessWindow();
                    currentProcessor = null;
                    currentJob       = null;

                    // Logging
                    addToLog("Processing ended at " + DateTime.Now.ToLongTimeString() + "\r\n");
                    addToLog("------------------------------------------------------" +
                             "\r\n\r\nLog for job " + su.JobName + "\r\n\r\n" + su.Log +
                             "\r\n------------------------------------------------------\r\n");

                    // Postprocessing
                    bool jobCompletedSuccessfully = (job.Status == JobStatus.DONE);
                    if (jobCompletedSuccessfully)
                    {
                        postprocessJob(job.Job);
                    }

                    if (jobCompletedSuccessfully && mainForm.Settings.DeleteCompletedJobs)
                    {
                        mainForm.Jobs.RemoveCompletedJob(job);
                    }

                    addToLog("End of log for " + job.Name + "\r\n" +
                             "------------------------------------------------------\r\n\r\n");

                    if (shutdownWorkerIfJobsCompleted())
                    {
                    }
                    else if (job.Status == JobStatus.ABORTED)
                    {
                        addToLog("The current job was aborted. Stopping queue mode\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else if (status == JobWorkerStatus.Stopping)
                    {
                        addToLog("Told to stop. Stopping queue mode.\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else
                    {
                        switch (startNextJobInQueue())
                        {
                        case JobStartInfo.JOB_STARTED:
                            break;

                        case JobStartInfo.COULDNT_START:
                            status = JobWorkerStatus.Idle;
                            break;

                        case JobStartInfo.NO_JOBS_WAITING:
                            status = JobWorkerStatus.Idle;
                            new Thread(delegate()
                            {
                                WorkerFinishedJobs(this, EventArgs.Empty);
                            }).Start();
                            break;
                        }
                    }

                    refreshAll();
                }));
                t.IsBackground = true;
                t.Start();
            }
            else // job is not complete yet
            {
                try
                {
                    if (pw.IsHandleCreated && pw.Visible) // the window is there, send the update to the window
                    {
                        pw.BeginInvoke(new UpdateStatusCallback(pw.UpdateStatus), su);
                    }
                }
                catch (Exception e)
                {
                    mainForm.addToLog("Exception when trying to update status while a job is running. Text: " + e.Message + " stacktrace: " + e.StackTrace);
                }

                progress = su.PercentageDoneExact ?? 0;
                updateProgress();

                /*
                 * string percentage = (su.PercentageDoneExact ?? 0M).ToString("##.##");
                 * if (percentage.IndexOf(".") != -1 && percentage.Substring(percentage.IndexOf(".")).Length == 1)
                 *  percentage += "0";
                 * mainForm.TitleText = "MeGUI " + su.JobName + " " + percentage + "% ";
                 * if (mainForm.Settings.AfterEncoding == AfterEncoding.Shutdown)
                 *  mainForm.TitleText += "- SHUTDOWN after encode";
                 * this.jobProgress.Value = su.PercentageDone;*/
            }
        }
Example #37
0
 private IJobProcessor InfiniteRetry(IJobProcessor inner)
 {
     return(new InfiniteRetryProcessor(inner, _loggerFactory));
 }