Exemplo n.º 1
0
        public override void Execute()
        {
            //retrieve ResourceServerId for agent for checking resource pool. this value will be used when retrieving records from queue
            ResourceServerId = SqlQueryHelper.GetResourceServerByAgentId(EddsDbContext, AgentId);
            if (ResourceServerId == 0)
            {
                TextExtractorLog.RaiseUpdate(string.Format("Resource Server for Agent ID {0} cannot be detected.", AgentId));
                return;
            }

            TextExtractorLog.RaiseUpdate("Processing Worker Queue Batch.");
            var workerQueue = new WorkerQueue(SqlQueryHelper, ArtifactQueries, ArtifactFactory, EddsDbContext, ServicesMgr, ExecutionIdentity, AgentId, ResourceServerId, BatchTableName, TextExtractorLog, TextExtractorJobReporting);

            if (workerQueue.HasRecords)
            {
                WorkspaceArtifactId = workerQueue.WorkspaceArtifactId;
                var extractorSet = ArtifactFactory.GetInstanceOfExtractorSet(ExecutionIdentity.CurrentUser, workerQueue.WorkspaceArtifactId, workerQueue.ExtractorSetArtifactId);

                //check for ExtractorSet cancellation
                Boolean isCancelled = CheckForExtractorSetCancellation(extractorSet, true);
                if (!isCancelled)
                {
                    //process worker queue records in current batch
                    workerQueue.ProcessAllRecords();

                    //check for ExtractorSet cancellation
                    CheckForExtractorSetCancellation(extractorSet, false);
                }
            }

            TextExtractorLog.RaiseUpdate("Worker Queue Batch processed.");
        }
Exemplo n.º 2
0
            public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery)
            {
                _work      = work;
                _pool      = pool;
                _workQueue = _work.WorkQueue;
                _work.ReplacePoolWorker(this, errorRecovery);

                _thread = new Thread(() =>
                {
                    CurrentWorker = this;

                    foreach (var action in _workQueue.GetConsumingEnumerable())
                    {
                        try
                        {
                            //bail if shutdown has been requested
                            if (_pool.ShutdownRequested)
                            {
                                return;
                            }
                            action();
                        }
                        catch (Exception ex)
                        {
                            Failover(true);
                            return;
                        }
                    }
                })
                {
                    IsBackground = _pool.Settings.ThreadType == ThreadType.Background
                };

                _thread.Start();
            }
Exemplo n.º 3
0
        public MessagingRoot(MessagingSerializationGraph serialization,
                             JasperOptions options,
                             HandlerGraph handlers,
                             ISubscriberGraph subscribers,
                             IMessageLogger messageLogger,
                             IContainer container,
                             ITransportLogger transportLogger
                             )
        {
            Options          = options;
            Handlers         = handlers;
            _transportLogger = transportLogger;
            Subscribers      = subscribers;
            Transports       = container.QuickBuildAll <ITransport>().ToArray();


            Serialization = serialization;

            Logger = messageLogger;

            Pipeline = new HandlerPipeline(Serialization, handlers, Logger,
                                           container.QuickBuildAll <IMissingHandler>(),
                                           this);

            Workers = new WorkerQueue(Logger, Pipeline, options);

            Router = new MessageRouter(this, handlers);

            _persistence = new Lazy <IEnvelopePersistence>(() => container.GetInstance <IEnvelopePersistence>());
        }
Exemplo n.º 4
0
        public MessagingRoot(MessagingSerializationGraph serialization,
                             JasperOptions settings,
                             HandlerGraph handlers,
                             IDurableMessagingFactory factory,
                             ISubscriberGraph subscribers,
                             IMessageLogger messageLogger,
                             IContainer container,
                             ITransportLogger transportLogger)
        {
            Settings         = settings;
            _handlers        = handlers;
            _transportLogger = transportLogger;
            Factory          = factory;
            Subscribers      = subscribers;
            Transports       = container.QuickBuildAll <ITransport>().ToArray();


            Serialization = serialization;

            Logger = messageLogger;

            Pipeline = new HandlerPipeline(Serialization, handlers, Logger,
                                           container.QuickBuildAll <IMissingHandler>(),
                                           this);

            Workers = new WorkerQueue(Logger, Pipeline, settings);

            Router = new MessageRouter(this, handlers);

            // TODO -- ZOMG this is horrible, and I admit it.
            if (Factory is NulloDurableMessagingFactory f)
            {
                f.ScheduledJobs = ScheduledJobs;
            }
        }
Exemplo n.º 5
0
 public override void Execute()
 {
     foreach (var count in Enumerable.Range(1, 10))
     {
         WorkerQueue.AddMessage(new CloudQueueMessage($"Queued message {count}"));
     }
 }
        public void Start()
        {
            renderQueue = new WorkerQueue();
            renderQueue.Start();

            generateQueue = new WorkerQueue();
            generateQueue.Start();
        }
Exemplo n.º 7
0
 private void Failover(bool errorRecovery = false)
 {
     /* request a new thread then shut down */
     _pool.RequestThread(_work, errorRecovery);
     CurrentWorker = null;
     _work         = null;
     _workQueue    = null;
     _pool         = null;
 }
Exemplo n.º 8
0
        private void BTN_Exit_Click(object sender, EventArgs e)
        {
            WorkerBarber.CancelAsync();
            WorkerQueue.CancelAsync();

            BTN_Start.Enabled     = true;
            BTN_Exit.Enabled      = false;
            BTN_NewClient.Enabled = false;
        }
        public override void Execute()
        {
            var batch = WorkerQueue.GetMessages(10, TimeSpan.FromMinutes(5));

            Parallel.ForEach(batch, m =>
            {
                Console.WriteLine(m.AsString);
            });
        }
Exemplo n.º 10
0
 static HelpDownloader()
 {
     Tasks   = new WorkerQueue <HelpCenterRequest>(1, TimeSpan.FromSeconds(60), 1, true);
     LockObj = new object();
     if (!bool.TryParse(WebConfigurationManager.AppSettings["web.help-center.download"] ?? "false", out DownloadEnabled))
     {
         DownloadEnabled = false;
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Complete and dispose of resources
        /// </summary>
        public new void Dispose()
        {
            WorkerQueue <EventData> worker = Interlocked.Exchange(ref _workerQueue, null);

            if (worker != null)
            {
                worker.OnCompleted();
                base.Dispose();
            }
        }
Exemplo n.º 12
0
 public void Start()
 {
     if (!Started)
     {
         Started  = true;
         requests = new WorkerQueue <string>(4, TimeSpan.Zero, 10, true);
         requests.AddRange(urls);
         requests.Start(LoaderPortalPages);
     }
 }
Exemplo n.º 13
0
 public FileMarkerHelper(
     IServiceProvider serviceProvider,
     IOptionsMonitor <ILog> optionsMonitor,
     WorkerQueueOptionsManager <AsyncTaskData <T> > workerQueueOptionsManager)
 {
     ServiceProvider = serviceProvider;
     Log             = optionsMonitor.CurrentValue;
     Locker          = new object();
     Tasks           = workerQueueOptionsManager.Value;
 }
Exemplo n.º 14
0
        private void queue()
        {
            if (nClients == 3)
            {
                WorkerQueue.ReportProgress(1);
                return;
            }

            nClients++;
            WorkerQueue.ReportProgress(0);
        }
Exemplo n.º 15
0
        public Topic(string name)
        {
            name.ArgumentNullException("name");

            this.name       = name;
            this.subscribes = new List <Action <IMessage> >();
            this.workQueue  = new WorkerQueue <IMessage>(DistributionHandler);
            this.lockSlim   = new ReaderWriterLockSlim();

            this.workQueue.Start();
        }
Exemplo n.º 16
0
        private void WorkerQueue_DoWork(object sender, DoWorkEventArgs e)
        {
            queue();
            WorkerQueue.CancelAsync();

            if (WorkerQueue.CancellationPending == true)
            {
                e.Cancel = true;
                return;
            }
        }
Exemplo n.º 17
0
 private LogHost()
 {
     _hostInfo             = HostUtil.GetHostInfo();
     _appKey               = AppContext.AppKey;
     _writeLogBatchSize    = AppContext.LogMaxMessageCount;
     _writeLogCoolDownTime = AppContext.LogSendFrequency;
     _localQueueSize       = AppContext.LogMaxQueueSize;
     _isWriteLocalLog      = AppContext.WriteLocalFile;
     _localLogQueue        = new WorkerQueue <LogContent>(_writeLogBatchSize, _writeLogCoolDownTime, _localQueueSize, "LogSDKQueue");
     _localLogQueue.Flush += new Action <object, List <LogContent> >(WriteLog);
 }
Exemplo n.º 18
0
        public void ExecuteTest()
        {
            var sequence = 0;
            var worker   = new WorkerQueue();

            worker.Execute(() => { Assert.AreEqual(0, sequence); Thread.Sleep(10); ++sequence; });
            worker.Execute(() => { Assert.AreEqual(1, sequence); Thread.Sleep(10); ++sequence; });
            worker.Execute(() => { Assert.AreEqual(2, sequence); Thread.Sleep(10); ++sequence; });
            worker.Execute(() => { Assert.AreEqual(3, sequence); Thread.Sleep(10); ++sequence; });
            worker.Execute(() => { Assert.AreEqual(4, sequence); Thread.Sleep(10); ++sequence; });

            Assert.AreEqual(5, sequence);
        }
Exemplo n.º 19
0
        /// <remarks>
        /// This method is thread safe.
        /// </remarks>
        public void QueueSync(ChatModel chatModel)
        {
            Trace.Call(chatModel);

            if (chatModel == null)
            {
                throw new ArgumentNullException("chatModel");
            }

            WorkerQueue.Enqueue(delegate {
                SyncWorker(chatModel);
            });
        }
Exemplo n.º 20
0
 public void Terminate()
 {
     try
     {
         if (requests != null)
         {
             requests.Terminate();
             requests = null;
         }
     }
     catch (ThreadAbortException)
     {
     }
 }
Exemplo n.º 21
0
        public void CurrentThreadOnTest()
        {
            var inCheck  = false;
            var outCheck = false;
            var worker   = new WorkerQueue();

            worker.Queue(() => { inCheck = worker.CurrentThreadOn(); });
            worker.Wait();

            outCheck = worker.CurrentThreadOn();

            Assert.IsTrue(inCheck);
            Assert.IsFalse(outCheck);
        }
Exemplo n.º 22
0
        public void QueueTest()
        {
            var sequence = 0;
            var worker   = new WorkerQueue();

            worker.Queue(() => { Assert.AreEqual(0, sequence); Thread.Sleep(100); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(1, sequence); Thread.Sleep(10); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(2, sequence); Thread.Sleep(0); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(3, sequence); Thread.Sleep(50); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(4, sequence); Thread.Sleep(150); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(5, sequence); Thread.Sleep(1); ++sequence; });
            worker.Wait();

            Assert.AreEqual(6, sequence);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Enqueue (Helper) | Executes a specific queue of computers to retrieve information, and update database.
        /// </summary>
        /// <param name="wq"></param>
        private static void ExecuteQueue(WorkerQueue wq)
        {
            // Check if ready
            if (wq != null && wq.Computers.Count > 0)
            {
                // Tell the rest of the world we are working really hard!
                wq.isEnqueued = true;

                // Work the queue.
                foreach (int id in wq.Computers)
                {
                    UpdateComputer(id);
                }
                // Tell the world we are done.
                wq.isEnqueued = false;
            }
        }
Exemplo n.º 24
0
        public MessagingRoot(ObjectPoolProvider pooling,
                             MessagingSettings settings,
                             HandlerGraph handlers,
                             Forwarders forwarders,
                             IDurableMessagingFactory factory,
                             IChannelGraph channels,
                             ISubscriptionsRepository subscriptions,
                             IMessageLogger messageLogger,
                             IEnumerable <ISerializerFactory> serializers,
                             IEnumerable <IMessageDeserializer> readers,
                             IEnumerable <IMessageSerializer> writers,
                             ITransport[] transports,
                             IEnumerable <IMissingHandler> missingHandlers,
                             IEnumerable <IUriLookup> lookups, ITransportLogger transportLogger)
        {
            Settings         = settings;
            _handlers        = handlers;
            _transportLogger = transportLogger;
            Replies          = new ReplyWatcher();
            Factory          = factory;
            Channels         = channels;
            Transports       = transports;



            Lookup = new UriAliasLookup(lookups);


            Serialization = new MessagingSerializationGraph(pooling, settings, handlers, forwarders, serializers,
                                                            readers, writers);

            Logger = messageLogger;

            Pipeline = new HandlerPipeline(Serialization, handlers, Replies, Logger, missingHandlers,
                                           this);

            Workers = new WorkerQueue(Logger, Pipeline, settings);

            Router = new MessageRouter(Serialization, channels, subscriptions, handlers, Logger, Lookup, settings);

            // TODO -- ZOMG this is horrible, and I admit it.
            if (Factory is NulloDurableMessagingFactory)
            {
                Factory.As <NulloDurableMessagingFactory>().ScheduledJobs = ScheduledJobs;
            }
        }
Exemplo n.º 25
0
        public void ClearTest()
        {
            var sequence = 0;
            var blocker  = new ManualResetEvent(false);
            var worker   = new WorkerQueue();

            worker.Queue(() => { Assert.AreEqual(0, sequence); blocker.WaitOne(); worker.Clear(); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(1, sequence); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(2, sequence); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(3, sequence); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(4, sequence); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(5, sequence); ++sequence; });
            blocker.Set();
            Thread.Sleep(50);

            Assert.AreEqual(1, sequence);
        }
        public override void Execute()
        {
            var keepWorking = true;

            while (keepWorking)
            {
                var message = WorkerQueue.GetMessage(TimeSpan.FromMinutes(5));

                if (message != null)
                {
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    keepWorking = false;
                }
            }
        }
Exemplo n.º 27
0
        public MessagingRoot(
            ObjectPoolProvider pooling,
            BusSettings settings,
            HandlerGraph handlers,
            Forwarders forwarders,
            IPersistence persistence,
            IChannelGraph channels,
            ISubscriptionsRepository subscriptions,
            IEnumerable <ISerializerFactory> serializers,
            IEnumerable <IMessageDeserializer> readers,
            IEnumerable <IMessageSerializer> writers,
            IMessageLogger[] loggers,
            ITransport[] transports,
            IEnumerable <IMissingHandler> missingHandlers,
            IEnumerable <IUriLookup> lookups)
        {
            _settings    = settings;
            _handlers    = handlers;
            _replies     = new ReplyWatcher();
            _persistence = persistence;
            _channels    = channels;
            _transports  = transports;



            Lookup = new UriAliasLookup(lookups);


            Serialization = new BusMessageSerializationGraph(pooling, settings, handlers, forwarders, serializers,
                                                             readers, writers);

            Logger = new CompositeMessageLogger(loggers);

            Pipeline = new HandlerPipeline(Serialization, handlers, _replies, Logger, missingHandlers,
                                           new Lazy <IServiceBus>(Build));

            Workers = new WorkerQueue(Logger, Pipeline, settings);

            Router = new MessageRouter(Serialization, channels, subscriptions, handlers, Logger, Lookup, settings);

            ScheduledJobs = new InMemoryScheduledJobProcessor();
        }
Exemplo n.º 28
0
        public void ProcessAllRecordsTest()
        {
            IntegrationSettings    testSettings        = new IntegrationSettings();
            IntegrationDBContext   testDBContext       = new IntegrationDBContext(testSettings.DBContextSettings);
            IntegrationServicesMgr testServiceManager  = new IntegrationServicesMgr(testSettings.RsapiSettings);
            SqlQueryHelper         testSqlQueryHelpers = new SqlQueryHelper();
            ArtifactQueries        artifactQueries     = new ArtifactQueries();
            ArtifactFactory        artifactFactory     = new ArtifactFactory(artifactQueries, testServiceManager, null);

            Int32                 agentId               = 1016595;
            Int32                 resourceServerId      = 1016158;
            string                batchTableName        = "[" + Constant.Names.TablePrefix + "Worker_" + Guid.NewGuid() + "_" + agentId + "]";
            TextExtractorLog      textExtractorLog      = new TextExtractorLog();
            ExtractorSetReporting extractorSetReporting = new ExtractorSetReporting(artifactQueries, testServiceManager);

            WorkerQueue workerQueue = new WorkerQueue(testSqlQueryHelpers, artifactQueries, artifactFactory, testDBContext, testServiceManager, ExecutionIdentity.System,
                                                      agentId, resourceServerId, batchTableName, textExtractorLog, extractorSetReporting);

            workerQueue.ProcessAllRecords();
        }
Exemplo n.º 29
0
        public MessagingRoot(
            MessagingSerializationGraph serialization,
            MessagingSettings settings,
            HandlerGraph handlers,
            IDurableMessagingFactory factory,
            IChannelGraph channels,
            ISubscriptionsRepository subscriptions,
            IMessageLogger messageLogger,
            Lamar.IContainer container,
            ITransportLogger transportLogger)
        {
            Settings         = settings;
            _handlers        = handlers;
            _transportLogger = transportLogger;
            Replies          = new ReplyWatcher();
            Factory          = factory;
            Channels         = channels;
            Transports       = container.QuickBuildAll <ITransport>().ToArray();



            Lookup = new UriAliasLookup(container.QuickBuildAll <IUriLookup>());


            Serialization = serialization;

            Logger = messageLogger;

            Pipeline = new HandlerPipeline(Serialization, handlers, Replies, Logger, container.QuickBuildAll <IMissingHandler>(),
                                           this);

            Workers = new WorkerQueue(Logger, Pipeline, settings);

            Router = new MessageRouter(Serialization, channels, subscriptions, handlers, Logger, Lookup, settings);

            // TODO -- ZOMG this is horrible, and I admit it.
            if (Factory is NulloDurableMessagingFactory f)
            {
                f.ScheduledJobs = ScheduledJobs;
            }
        }
            public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery, int workerNumber)
            {
                _work         = work;
                _pool         = pool;
                _workerNumber = workerNumber;
                _workQueue    = _work.WorkQueue;
                _work.ReplacePoolWorker(this, errorRecovery);

                _thread = new Thread(() =>
                {
                    Thread.CurrentThread.Name = string.Format("{0}_{1}", pool.Settings.Name, _workerNumber);
                    CurrentWorker             = this;

                    foreach (var action in _workQueue.GetConsumingEnumerable())
                    {
                        try
                        {
                            //bail if shutdown has been requested
                            if (_pool.ShutdownRequested)
                            {
                                return;
                            }
                            action();
                        }
                        catch (Exception)
                        {
                            Failover(true);
                            return;
                        }
                    }
                })
                {
                    IsBackground = _pool.Settings.ThreadType == ThreadType.Background
                };
                if (_pool.Settings.ApartmentState != ApartmentState.Unknown)
                {
                    _thread.SetApartmentState(_pool.Settings.ApartmentState);
                }

                _thread.Start();
            }
 private void Failover(bool errorRecovery = false)
 {
     /* request a new thread then shut down */
     _pool.RequestThread(_work, errorRecovery);
     CurrentWorker = null;
     _work = null;
     _workQueue = null;
     _pool = null;
 }
            public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery)
            {
                _work = work;
                _pool = pool;
                _workQueue = _work.WorkQueue;
                _work.ReplacePoolWorker(this, errorRecovery);

                _thread = new Thread(() =>
                {
                    CurrentWorker = this;

                    foreach (var action in _workQueue.GetConsumingEnumerable())
                    {
                        try
                        {
                            //bail if shutdown has been requested
                            if (_pool.ShutdownRequested) return;
                            action();
                        }
                        catch (Exception ex)
                        {
                            Failover(true);
                            return;
                        }
                    }
                })
                {
                    IsBackground = _pool.Settings.ThreadType == ThreadType.Background
                };

                _thread.Start();
            }
 private PoolWorker RequestThread(WorkerQueue unclaimedQueue, bool errorRecovery = false)
 {
     var worker = new PoolWorker(unclaimedQueue, this, errorRecovery);
     return worker;
 }
Exemplo n.º 34
0
 public void Start()
 {
     if (!Started)
     {
         Started = true;
         requests = new WorkerQueue<string>(4, TimeSpan.Zero, 10, true);
         requests.AddRange(urls);
         requests.Start(LoaderPortalPages);
     }
 }
Exemplo n.º 35
0
        public void Terminate()
        {
            try
            {
                if (requests != null)
                {
                    requests.Terminate();
                    requests = null;
                }
            }
            catch (ThreadAbortException)
            {
            }

        }
            public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery, int workerNumber)
            {
                _work = work;
                _pool = pool;
                _workerNumber = workerNumber;
                _workQueue = _work.WorkQueue;
                _work.ReplacePoolWorker(this, errorRecovery);
                
                _thread = new Thread(() =>
                {
                    Thread.CurrentThread.Name = string.Format("{0}_{1}", pool.Settings.Name, _workerNumber);
                    CurrentWorker = this;

                    foreach (var action in _workQueue.GetConsumingEnumerable())
                    {
                        try
                        {
                            //bail if shutdown has been requested
                            if (_pool.ShutdownRequested) return;
                            action();
                        }
                        catch (Exception)
                        {
                            Failover(true);
                            return;
                        }
                    }
                })
                {
                    IsBackground = _pool.Settings.ThreadType == ThreadType.Background
                };
                if (_pool.Settings.ApartmentState != ApartmentState.Unknown)
                    _thread.SetApartmentState(_pool.Settings.ApartmentState);

                _thread.Start();
            }