<commit_before>using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;

namespace JenkinsConsoleUtility.Commands
{
    class KillTaskCommand : ICommand
    {
        private const int TASK_KILL_DELAY_MS = 15000;
        private const int TASK_KILL_SLEEP_MS = 500;

        public string commandKey { get { return "kill"; } }

        public int Execute(Dictionary<string, string> inputs)
        {
            string taskName;
            if (!inputs.TryGetValue("taskname", out taskName))
                return 1;

            List<Process> hitList = new List<Process>();
            hitList.AddRange(Process.GetProcessesByName(taskName));
            foreach (var eachProcess in hitList)
            {
                JenkinsConsoleUtility.FancyWriteToConsole("Closing task: " + eachProcess.ProcessName, null, ConsoleColor.Yellow);
                eachProcess.CloseMainWindow(); // Gently close the target so they don't throw error codes 
            }

            // Sleep for a while and wait for the programs to close safely
            int openCount = hitList.Count;
            for (int i = 0; i < TASK_KILL_DELAY_MS; i += TASK_KILL_SLEEP_MS)
            {
                Thread.Sleep(TASK_KILL_SLEEP_MS);
                openCount = 0;
                foreach (var eachProcess in hitList)
                {
                    if (!eachProcess.HasExited)
                        openCount += 1;
                }
                if (openCount == 0)
                    break;
            }

            // Time's up, close everything
            foreach (var eachProcess in hitList)
            {
                if (eachProcess.HasExited)
                    continue; // Finished skip it
                JenkinsConsoleUtility.FancyWriteToConsole("Killing task: " + eachProcess.ProcessName, null, ConsoleColor.Red);
                eachProcess.Kill(); // If it didn't close gently, then close it better.
            }

            return hitList.Count > 0 ? 0 : 1;
        }
    }
}<commit_msg>Minor improvement to task-kill reporting.<commit_after>using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;

namespace JenkinsConsoleUtility.Commands
{
    class KillTaskCommand : ICommand
    {
        private const int TASK_KILL_DELAY_MS = 15000;
        private const int TASK_KILL_SLEEP_MS = 500;

        public string commandKey { get { return "kill"; } }

        public int Execute(Dictionary<string, string> inputs)
        {
            string taskName;
            if (!inputs.TryGetValue("taskname", out taskName))
            {
                JenkinsConsoleUtility.FancyWriteToConsole("Cannot find the process to kill", null, ConsoleColor.Red);
                return 1;
            }

            List<Process> hitList = new List<Process>();
            hitList.AddRange(Process.GetProcessesByName(taskName));
            foreach (var eachProcess in hitList)
            {
                JenkinsConsoleUtility.FancyWriteToConsole("Closing task: " + eachProcess.ProcessName, null, ConsoleColor.Yellow);
                eachProcess.CloseMainWindow(); // Gently close the target so they don't throw error codes 
            }

            // Sleep for a while and wait for the programs to close safely
            int openCount = hitList.Count;
            for (int i = 0; i < TASK_KILL_DELAY_MS; i += TASK_KILL_SLEEP_MS)
            {
                Thread.Sleep(TASK_KILL_SLEEP_MS);
                openCount = 0;
                foreach (var eachProcess in hitList)
                {
                    if (!eachProcess.HasExited)
                        openCount += 1;
                }
                if (openCount == 0)
                    break;
            }

            // Time's up, close everything
            foreach (var eachProcess in hitList)
            {
                if (eachProcess.HasExited)
                    continue; // Finished skip it
                JenkinsConsoleUtility.FancyWriteToConsole("Killing task: " + eachProcess.ProcessName, null, ConsoleColor.Red);
                eachProcess.Kill(); // If it didn't close gently, then close it better.
            }

            if (hitList.Count == 0)
                JenkinsConsoleUtility.FancyWriteToConsole("No tasks to kill: " + taskName, null, ConsoleColor.Red);
            return hitList.Count > 0 ? 0 : 1;
        }
    }
}
{'fraction_non_alphanumeric': 0.07937584803256445, 'fraction_numerical': 0.007462686567164179, 'mean_word_length': 1.718500307314075, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1368157', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1130, 'n_words': 306}