Exemplo n.º 1
0
        public async Task HandleAsync(CleanupHangingTasksEvent evt, CancellationToken ct)
        {
            // Find all running tasks in system
            var runningTasks = await _tasksRepository.GetAllRunningTasks(0, 10000);

            LogHandler.WriteLineVerbose($"Fetching running tasks: {runningTasks.Count()}");
            // If there is any running task in the system ensure that they are not hanging by matching their hostname
            // with all currently running pods...
            if (runningTasks.Any())
            {
                // Get all running nextpipe-deployment hosts
                var hosts = await _kubectlHelper.GetPodsByCustomNameFilter(NEXTPIPE_DEPLOYMENT,
                                                                           ShellHelper.IdenticalStart);

                //Iterate each task and if the tasks host is not running clean up the task
                foreach (var task in runningTasks)
                {
                    if (!hosts.Any(t => t.Metadata.Name.Trim().ToLower().Equals(task.Hostname.Trim().ToLower())))
                    {
                        LogHandler.WriteLineVerbose($"Task: {task.TaskId} of type: {task.TaskType} is scheduled on dead host: {task.Hostname} - Doing Cleanup");
                        await CleanupTask(task);
                    }
                }
            }
        }