<commit_before>﻿using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using Codestellation.Galaxy.ServiceManager;

namespace Codestellation.Galaxy.Domain
{
    public class DeploymentTaskProcessor : IDisposable
    {
        private readonly BlockingCollection<DeploymentTask> _taskQueue;
        private readonly CancellationTokenSource _cancellationSource;
        private readonly Task _processingTask;

        public DeploymentTaskProcessor()
        {
            _taskQueue = new BlockingCollection<DeploymentTask>();
            _cancellationSource = new CancellationTokenSource();
            _processingTask = Task.Run((Action)ProcessInternal);
        }

        public void Process(DeploymentTask task)
        {
            _taskQueue.Add(task);
        }

        private void ProcessInternal()
        {
            try
            {
                foreach (var task in _taskQueue.GetConsumingEnumerable(_cancellationSource.Token))
                {
                    task.Process();
                }
            }
            catch (OperationCanceledException)
            {
                //Operation cancelled by cancellation source
            }
        }

        public void Dispose()
        {
            if (_cancellationSource.IsCancellationRequested)
            {
                return;
            }

            _cancellationSource.Cancel();
            _processingTask.Wait();
        }
    }
}<commit_msg>Fixed deployment task processor (close #28)<commit_after>﻿using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using Codestellation.Galaxy.ServiceManager;
using NLog;

namespace Codestellation.Galaxy.Domain
{
    public class DeploymentTaskProcessor : IDisposable
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

        private readonly BlockingCollection<DeploymentTask> _taskQueue;
        private readonly CancellationTokenSource _cancellationSource;
        private readonly Task _processingTask;

        public DeploymentTaskProcessor()
        {
            _taskQueue = new BlockingCollection<DeploymentTask>();
            _cancellationSource = new CancellationTokenSource();
            _processingTask = Task.Run((Action)ProcessInternal);
        }

        public void Process(DeploymentTask task)
        {
            _taskQueue.Add(task);
        }

        private void ProcessInternal()
        {
            DeploymentTask temp = null;
            try
            {
                foreach (var task in _taskQueue.GetConsumingEnumerable(_cancellationSource.Token))
                {
                    temp = task;
                    task.Process();
                }
            }
            catch (OperationCanceledException)
            {
                //Operation cancelled by cancellation source
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Error processing task '{0}'", temp.Name);
            }
        }

        public void Dispose()
        {
            if (_cancellationSource.IsCancellationRequested)
            {
                return;
            }

            _cancellationSource.Cancel();
            _processingTask.Wait();
        }
    }
}
{'fraction_non_alphanumeric': 0.06861269936804093, 'fraction_numerical': 0.0009027986758952753, 'mean_word_length': 1.8050632911392406, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2002352', 'n_tokens_mistral': 796, 'n_tokens_neox': 767, 'n_words': 163}