Exemple #1
0
 private void LogTaskStarted(IWorkerTask task)
 {
     if (log.IsDebugEnabled && !ReferenceEquals(task, EndOfTaskMarker))
     {
         log.Debug($"Task '{task.Id}' was chosen to run. {progress.DumpTasksStat()}");
     }
 }
Exemple #2
0
 private void LogTaskFinished(IWorkerTask task, TimeSpan elapsed)
 {
     if (log.IsDebugEnabled && !ReferenceEquals(task, EndOfTaskMarker))
     {
         log.Debug($"Task '{task.Id}' executed at {elapsed}. {progress.DumpTasksStat()}");
     }
 }
Exemple #3
0
            private void ExecuteTask(IWorkerTask task)
            {
                var stopwatch = new Stopwatch();

                stopwatch.Start();

                progress.StartNewTask();
                LogTaskStarted(task);

                try
                {
                    if (isCanceled)
                    {
                        return;
                    }

                    task.Execute();

                    progress.EndTask();
                }
                finally
                {
                    stopwatch.Stop();
                    LogTaskFinished(task, stopwatch.Elapsed);
                }
            }
Exemple #4
0
 private void LogTaskWasEnqueue(IWorkerTask task)
 {
     if (log.IsDebugEnabled)
     {
         log.Debug($"Task '{task.Id}' was enqueue. {progress.DumpTasksStat()}");
     }
 }
Exemple #5
0
        public static void QueueTask(IWorkerTask workerTask)
        {
            using (var repository = ContainerBootstrapper.Container.Resolve <IRepository <WorkerTask> >())
            {
                var task = (WorkerTask)workerTask;
                task.Added = DateTime.Now;

                repository.Add(task);
            }

            ProcessQueue();
        }
Exemple #6
0
        public void PushTask([NotNull] IWorkerTask task)
        {
            CheckDisposed();

            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            lock (syncObject)
            {
                taskQueue.Enqueue(task);
                progress.TaskQueueSize = taskQueue.Count;
                LogTaskWasEnqueue(task);
                Monitor.PulseAll(syncObject);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WorkerTaskEventArgs"/> class.
 /// </summary>
 /// <param name="workerTask">The worker task that the event occurred on.</param>
 /// <param name="triggeredAt">The date/time the task was triggered at, not
 /// the event itself.</param>
 public WorkerTaskEventArgs(IWorkerTask workerTask, DateTime triggeredAt)
 {
     TriggeredAt = triggeredAt;
     Task        = workerTask;
 }
 protected WorkerAgent(IWorkerTask task)
 {
     Task = task;
 }