Example #1
0
        private ITrigger GetSpecialTrigger(SpecialTrigger type, XmlNode node)
        {
            ITriggerFactory factory = mTriggerFactories.FirstOrDefault(f => f.Special == type && f.Mode == mMode);

            if (factory == null)
            {
                Logger.Debug("Unable to load " + type + " trigger from " + node.Name + ". No trigger factory mapped for " + mMode + ". Check the ninject configuration file.");
                return(null);
            }

            return(mClipLoaded ? factory.Create(this, node, mClip) : factory.Create(this, node));
        }
        private async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                if (_scheduler.IsStarted)
                {
                    continue;
                }

                var jobCount = 0;

                try
                {
                    await _scheduler.Start();

                    foreach (var job in _jobs)
                    {
                        using (_logger.AddContext("JobId", job.Id))
                        {
                            if (await _scheduler.CheckExists(new JobKey(job.Id)))
                            {
                                continue;
                            }

                            var triggerOkorFail = _factory.Create(job.Id, job.GroupId);
                            if (!triggerOkorFail.Success)
                            {
                                _logger.Warn(string.Join(" ", triggerOkorFail.Error));
                                continue;
                            }

                            IJobDetail dtl = JobBuilder.Create(job.GetType())
                                             .WithIdentity(job.Id, job.GroupId)
                                             .WithDescription(job.Description)
                                             .Build();

                            _logger.Verbose($"Scheduling job: {job.Id}");

                            await _scheduler.ScheduleJob(dtl, triggerOkorFail.Value);

                            jobCount++;
                        }
                    }

                    _logger.Information("{JobCount} of {JobTotal} job(s) scheduled successfully", jobCount, _jobs.Count());
                }
                catch (Exception e)
                {
                    _logger.Error(e);
                }
            }

            if (cancellationToken.IsCancellationRequested)
            {
                if (!_scheduler.IsShutdown)
                {
                    await _scheduler.Shutdown(waitForJobsToComplete : true);
                }
            }
        }