Esempio n. 1
0
 public Feed()
 {
     string address = ConfigurationManager.AppSettings["GatewayServerAddress"];
     _pushers = address.Split(';').Select(adr => new NetMqPusher(adr)).ToArray();
     _worker = new TaskWorker(GenerateFeed);
     _clusterMonitor = CreateCluster();
 }
Esempio n. 2
0
        public Feed()
        {
            string address = ConfigurationManager.AppSettings["GatewayServerAddress"];

            _pushers        = address.Split(';').Select(adr => new NetMqPusher(adr)).ToArray();
            _worker         = new TaskWorker(GenerateFeed);
            _clusterMonitor = CreateCluster();
        }
Esempio n. 3
0
        /// <summary>
        /// Starts a task.
        /// </summary>
        /// <remarks>This method should be called only once.</remarks>
        /// <param name="worker">The task worker to extend.</param>
        /// <param name="task">The task to be started by the task worker.</param>
        /// <exception cref="ArgumentNullException">Parameter <paramref name="worker"/> or <paramref name="task"/> is null.</exception>
        public static void StartTask(this ITaskWorker worker, ITask task)
        {
            if (worker == null)
            {
                throw new ArgumentNullException(nameof(worker));
            }

            worker.StartTask(task, null);
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the TaskProcessor class
 /// </summary>
 /// <param name="worker">the worker that is used to process tasks</param>
 /// <param name="workerPulse">an object that is used to pulse this worker when new tasks have arrived</param>
 /// <param name="stopEvent">a reset event used to stop this processor</param>
 /// <param name="workerPollTime">the pollTime after which a new poll cycle is started when no further intervetion is done</param>
 /// <param name="highestPriority">the highest priority that is processed by this worker</param>
 /// <param name="lowestPriority">the lowest priority that is processed by this worker</param>
 /// <param name="parent">the parent from which this processor gets tasks to process</param>
 /// <param name="tasks">the task queues that are used to process tasks</param>
 internal AsyncTaskProcessor(ITaskWorker worker, object workerPulse, System.Threading.ManualResetEvent stopEvent,
                             int workerPollTime, int highestPriority, int lowestPriority,
                             ParallelTaskProcessor parent,
                             Dictionary <int, System.Collections.Concurrent.ConcurrentQueue <TaskContainer> > tasks)
     : this()
 {
     this.worker          = worker;
     this.workerPulse     = workerPulse;
     this.stopEvent       = stopEvent;
     this.workerPollTime  = workerPollTime;
     this.highestPriority = highestPriority;
     this.lowestPriority  = lowestPriority;
     this.tasks           = tasks;
     this.parent          = parent;
     ((ITaskProcessor)this).StartupThread();
     BuildProcessCycle();
     lastActivity = DateTime.Now;
     enterprocessingLoopWait.Set();
 }
Esempio n. 5
0
 public void RegisterTaskWorker(ITaskWorker worker)
 {
     this.TaskWorkers.Add(worker);
 }
Esempio n. 6
0
 public TaskReceiver(ITaskWorker taskWorker)
 {
     this.taskWorker = taskWorker;
 }
Esempio n. 7
0
 private async Task TryStopWorkerAsync(ITaskWorker worker)
 {
     using (worker)
         await worker.StopAync();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessObjectHostedService"/> class.
 /// </summary>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="worker">The worker to process objects.</param>
 public ProcessObjectHostedService(ILoggerFactory loggerFactory, ITaskWorker worker)
 {
     logger      = loggerFactory.CreateLogger <ProcessObjectHostedService>();
     this.worker = worker;
 }
Esempio n. 9
0
        public void StartTask(Guid taskId)
        {
            ITask task = this.repository.Tasks.GetById(taskId);

            if (task == null)
            {
                throw new ArgumentException("Task '{0}' was not found in storage.".FormatInvariant(taskId), "taskId");
            }

            ITaskWorker taskWorker = this.taskFactory.CreateTaskWorker(task);

            ITaskMessageBusSender taskMessageBus = this.messageBus.Tasks.GetSender(task.GetType());

            taskWorker.ReportProgress += (sender, e) =>
            {
                this.repository.TaskRuntimeInfo.Progress(taskId, e.Percentage);

                taskMessageBus.NotifyTaskProgress(taskId, e.Percentage);
            };

            this.messageBus.Tasks.Receiver.SubscribeForChannels(MessageBusChannel.TaskCancelRequest);

            bool isCanceled = false;

            this.messageBus.Tasks.Receiver.TaskCancelRequested += (_, e1) =>
            {
                if (!isCanceled && (e1.TaskId == taskId))
                {
                    isCanceled = true;

                    taskWorker.CancelTask();
                }
            };

            ITaskJobSettings settings = null;

            ITaskWorkerConfiguration config = this.configuration[task.GetType()];

            if ((config != null) && config.HasTaskJobSettings)
            {
                settings = this.repository.TaskJobSettings.Get(task.GetType());
            }

            ITaskRuntimeInfo taskInfo = this.repository.TaskRuntimeInfo.GetById(taskId);

            if (taskInfo == null)
            {
                throw new ArgumentException("Task '{0}' not found in storage.".FormatInvariant(taskId), "taskId");
            }

            switch (taskInfo.Status)
            {
            case TaskStatus.Pending:
            case TaskStatus.InProgress:
                break;

            case TaskStatus.Canceled:
                throw new OperationCanceledException();

            default:
                throw new ArgumentException("Task '{0}' status is '{1}'.".FormatInvariant(taskId, taskInfo.Status), "taskId");
            }

            try
            {
                try
                {
                    taskWorker.StartTask(task, settings);
                }
                catch (Exception ex)
                {
                    this.repository.TaskRuntimeInfo.Fail(taskId, this.dateTimeProvider.UtcNow, ex);

                    throw;
                }
            }
            finally
            {
                this.messageBus.Tasks.Receiver.UnsubscribeFromAllChannels();

                if (taskWorker is IDisposable)
                {
                    ((IDisposable)taskWorker).Dispose();
                }
            }
        }