Ejemplo n.º 1
0
 public void UnlockTask(GridJobTask task)
 {
     if (_lockedTasks.Contains(task))
     {
         _lockedTasks.Remove(task);
     }
 }
Ejemplo n.º 2
0
        public PacketWorkerTaskRequest(GridJobTask task)
        {
            _jobSerialized     = task.ParentJob.Serialize(true);
            _jobTaskSerialized = task.Serialize(true);

            _lastRequestId++;
        }
Ejemplo n.º 3
0
        public GridJobTask GetTask()
        {
            var job  = GridJob.Deserialize(_jobSerialized);
            var task = GridJobTask.Deserialize(_jobTaskSerialized);

            task.ParentJob = job;
            return(task);
        }
Ejemplo n.º 4
0
        public bool RunNewTask(GridJobTask task)
        {
            if (_activeTask != null)
            {
                return(false);
            }

            _activeTask = task;
            _taskWaitEvent.Set();
            return(true);
        }
Ejemplo n.º 5
0
        public void WorkerCancelActiveTask(uint taskId, string jobName)
        {
            if (_activeTask == null)
            {
                return;
            }

            if (_activeTask.ParentJob.Name == jobName && _activeTask.TaskId == taskId)
            {
                _gridServer.UnlockTask(_activeTask);
                IsAcceptingNewTasks = !_isDisconnecting;
                _activeTask         = null;
            }
        }
Ejemplo n.º 6
0
        public GridJobTask CreateTask(GridJobFile moduleFile, GridJobFile inputFile, string outputFile, long startPos, long endPos, string searchHaystack, uint taskId)
        {
            var task = new GridJobTask {
                TaskId        = taskId,
                ModuleFileRef = moduleFile.GetLink(),
                Arguments     = new [] {
                    inputFile.FileName,
                    startPos.ToString(),
                    endPos.ToString(),
                    outputFile,
                    searchHaystack
                }
            };

            task.ReferencedFiles.Add(inputFile.GetLink());
            return(task);
        }
Ejemplo n.º 7
0
        public override void ExecuteTask(GridTaskExecutor executor, GridJobTask task, ILog logger)
        {
            var inputFilePath = GridIo.ResolveFilePathShared(task.ParentJob, task.Arguments[0]);

            if (!File.Exists(inputFilePath))
            {
                throw new Exception($"Unable to load task input file '{task.Arguments[0]}', not found by present path '{inputFilePath}'");
            }

            byte[] buffer;
            using (var fs = new FileStream(inputFilePath, FileMode.Open, FileAccess.Read)) {
                var startPos = long.Parse(task.Arguments[1]);
                var endPos   = long.Parse(task.Arguments[2]);

                buffer = new byte[endPos - startPos];
                fs.Seek(startPos, SeekOrigin.Begin);
                fs.Read(buffer, 0, buffer.Length);
            }

            var needleCount  = 0;
            var needleString = task.Arguments[4];

            using (var sr = new StreamReader(new MemoryStream(buffer))) {
                var all = sr.ReadToEnd();

                for (var i = 0; i < all.Length; i++)
                {
                    if (SearchSubstringAt(all, needleString, i))
                    {
                        needleCount++;
                        i += needleString.Length;
                    }
                }
            }

            logger.Info($"Find '{needleCount}' in block");
            executor.WriteFileOutput(task, task.Arguments[3], $"{needleCount}");
        }
Ejemplo n.º 8
0
 public PacketWorkerTaskFinish(GridJobTask task)
 {
     _taskId   = task.TaskId;
     _jobName  = task.ParentJob.Name;
     _jobState = task.State;
 }
Ejemplo n.º 9
0
 public void RequestExecTask(GridJobTask task)
 {
     _activeTask         = task;
     IsAcceptingNewTasks = false;
     SendPacket(new PacketWorkerTaskRequest(task));
 }
Ejemplo n.º 10
0
        public void TickMain()
        {
            _taskWaitEvent.WaitOne();
            if (_activeTask == null)
            {
                _taskWaitEvent.Reset();
                return;
            }

            if (_activeTask.State == EGridJobTaskState.Created)
            {
                GridIo.CleanupTasksDirectoriesOnly(_activeTask.ParentJob);
                _networkSystem.CleanupWaitFiles();

                Logger.Info($"New task {_activeTask} is received from server");
                _activeTask.State = EGridJobTaskState.Running;

                foreach (var refFile in _activeTask.ReferencedFiles)
                {
                    var fileOriginal = refFile.ResolveLink(_activeTask.ParentJob);
                    if (fileOriginal == null)
                    {
                        Logger.Error($"Unable to resolve referenced file {refFile}");
                        _activeTask.State = EGridJobTaskState.RunningFailed;
                        return;
                    }

                    var reqFiles = 0;
                    if (!GridIo.IsJobTaskFileExistsAndValid(_activeTask, fileOriginal))
                    {
                        _networkSystem.AddWaitFile(fileOriginal);
                        Logger.Info($"Requesting {fileOriginal} from server (not exists locally, or checksum invalid)");
                        _networkSystem.SendPacket(new PacketWorkerFileRequest(_activeTask.TaskId, _activeTask.ParentJob.Name, fileOriginal));
                        reqFiles++;
                    }

                    if (reqFiles > 0)
                    {
                        Logger.Info($"Wait {reqFiles} files to download from server");
                    }
                }

                while (true)
                {
                    if (_networkSystem.AllWaitFilesReceived())
                    {
                        Logger.Info("All files for task are received");
                        break;
                    }
                }

                try {
                    Logger.Info($"Processing task {_activeTask}");
                    _activeTask.ExecuteModuleTask(new GridTaskExecutor(), Logger);
                    _activeTask.State = EGridJobTaskState.RunningFinished;
                    Logger.Info($"Task {_activeTask} is finished");
                } catch (GridJobTaskCommandException e) {
                    _activeTask.State = EGridJobTaskState.RunningFailed;
                    Logger.Error("Task execute internal error", e);
                } catch (Exception e) {
                    _activeTask.State = EGridJobTaskState.RunningFailed;
                    Logger.Error("Task execute unexpected error", e);
                }
            }

            if (_activeTask.State == EGridJobTaskState.RunningFinished || _activeTask.State == EGridJobTaskState.RunningFailed)
            {
                try {
                    if (_activeTask.State == EGridJobTaskState.RunningFinished)
                    {
                        Logger.Info($"Sending task {_activeTask} output files");
                        SendOutputFiles();
                    }

                    _networkSystem.SendPacket(new PacketWorkerTaskFinish(_activeTask));
                } catch (Exception e) {
                    Logger.Error("Unable to send task finished packet", e);
                } finally {
                    _activeTask = null;
                }
            }
        }
Ejemplo n.º 11
0
 public PacketWorkerTaskResponse(GridJobTask task, bool isAccept)
 {
     _taskId   = task.TaskId;
     _jobName  = task.ParentJob.Name;
     _isAccept = isAccept;
 }
Ejemplo n.º 12
0
 public PacketWorkerTaskCancel(GridJobTask task)
 {
     _taskId  = task.TaskId;
     _jobName = task.ParentJob.Name;
 }
Ejemplo n.º 13
0
 public PacketWorkerFileData(GridJobTask task, GridJobFile file)
 {
     _jobName = task.ParentJob.Name;
     _taskId  = task.TaskId;
     _file    = file;
 }