public static void ExecuteBlocking(this BaseScheduler scheduler, IFileSource fileSource, int timeout = 5000)
        {
            var resetEvent = new ManualResetEventSlim();

            scheduler.Executor.LifeCycleEvent += Unlock;

            var methodInfo = typeof(BaseScheduler).GetMethod("Execute", BindingFlags.NonPublic | BindingFlags.Instance,
                                                             null, new[] { typeof(IFileSource) }, null)
                             ?? throw new MissingMethodException("Execute could not be found");

            methodInfo.Invoke(scheduler, new object[] { fileSource });

            if (resetEvent.Wait(timeout))
            {
                scheduler.Executor.LifeCycleEvent -= Unlock;
            }
            else
            {
                throw new TimeoutException("The file source has not been processed in the defined amount of time.");
            }

            void Unlock(object sender, ExecutorLifeCycleEventArgs args)
            {
                if (args.EventType == ExecutorLifeCycleEventType.SourceExecutionFinished &&
                    ReferenceEquals(args.FileSource, fileSource))
                {
                    resetEvent.Set();
                }
            }
        }
Exemplo n.º 2
0
        public ActionQueueScheduler()
        {
            _actionFactory = new ActionFactory();
            _log.Log.Info("Configure Timer start");
            var minutes = 1;

            _scheduler = new BaseScheduler(1000 * 60 * minutes);
            _log.Log.InfoFormat("Configure Timer end. Interval {0} minutes", 1);
        }
Exemplo n.º 3
0
        public ActionQueueScheduler(BaseLogger log, QueueRepository repo)
        {
            _log           = log;
            _repo          = repo;
            _actionFactory = new ActionFactory(log, repo);
            _log.Log.Info("Configure Timer start");
            var minutes = Configuration.Configuration.Get.ActivationQueue.ActionQueueProcessingInterval;

            _scheduler = new BaseScheduler(1000 * 60 * minutes);
            _log.Log.InfoFormat("Configure Timer end. Interval {0} minutes", minutes);
        }
        ///
        /// <summary>
        ///     Initialize min scheduler
        /// </summary>
        ///
        public override void Initialize()
        {
            // HACK use 30ms for now to give time for debug output.
            // If busy, don't run for more than 10ms on same task.
            TimeSpan minSlice = TimeSpan.FromMilliseconds(10);

            schedulers = new BaseScheduler [Processor.processorTable.Length];

            // Create the idle threads and put them on the idleThreads loop.
            for (int i = 0; i < Processor.processorTable.Length; i++)
            {
                // Create scheduler
                schedulers[i] = BaseSchedulerManager.CreateScheduler(minSlice, i);
            }

            // Wait until first dispatcher will call into the scheduler
            numberOfActiveDispatchers = 0;
        }