示例#1
0
        public static void StoreJobTaskOutputFile(GridJobTask task, string file, byte[] data)
        {
            CreateTaskDirectoriesIfNotExists(task);

            var fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}\\{file}";

            File.WriteAllBytes(fp, data);
        }
示例#2
0
        public static string ResolveFilePath(GridJob job, GridJobTask task, GridJobFile file)
        {
            if (file.ShareMode == EGridJobFileShare.SharedBetweenTasks)
            {
                return($"{JobsDirectory}\\{job.Name}\\{file.FileName}");
            }

            return($"{JobsDirectory}\\{job.Name}\\task-{task.TaskId}\\{file.FileName}");
        }
示例#3
0
        public static bool CreateTaskDirectoriesIfNotExists(GridJobTask task)
        {
            if (!CheckIfTaskDirectoriesExists(task))
            {
                Directory.CreateDirectory($"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}");
                return(true);
            }

            return(false);
        }
示例#4
0
        public static void CreateDirectoriesForTask(GridJobTask task)
        {
            if (CreateTaskDirectoriesIfNotExists(task))
            {
                return;
            }

            CleanupDirectory($"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}");
            CreateDirectoriesForTask(task);
        }
示例#5
0
        public static void StoreJobTaskFile(GridJobTask task, GridJobFile file)
        {
            CreateTaskDirectoriesIfNotExists(task);

            var fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}\\{file.FileName}";

            if (file.ShareMode == EGridJobFileShare.SharedBetweenTasks)
            {
                fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\{file.FileName}";
            }

            File.WriteAllBytes(fp, file.Bytes);
        }
示例#6
0
        public static bool IsJobTaskFileExistsAndValid(GridJobTask task, GridJobFile jobFile)
        {
            var fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\{jobFile.FileName}";

            if (jobFile.ShareMode == EGridJobFileShare.SharedBetweenTasks)
            {
                if (!File.Exists(fp))
                {
                    return(false);
                }

                return(CryptoUtils.CrcOfFile(fp) == jobFile.CheckSum);
            }

            fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}\\{jobFile.FileName}";
            if (!File.Exists(fp))
            {
                return(false);
            }

            return(CryptoUtils.CrcOfFile(fp) == jobFile.CheckSum);
        }
示例#7
0
        private static GridJobModule LoadModule(GridJobTask task, GridJobFileLink link)
        {
            var moduleFile = task.ParentJob.JobFiles.FirstOrDefault(x => x.FileName == link.FileName);

            if (moduleFile == null)
            {
                throw new GridJobTaskCommandException(task, $"Unable to locate referenced module file {link} in task instance");
            }

            moduleFile.Bytes = File.ReadAllBytes(GridIo.ResolveFilePath(task, moduleFile));
            moduleFile.UpdateCheckSum();

            Assembly assembly;

            try {
                assembly = Assembly.Load(moduleFile.Bytes);
            } catch (Exception e) {
                throw new GridJobTaskCommandException(task, $"Unable to load module assembly file {link} when try to execute task", e);
            }

            var entryPoint = assembly.GetExportedTypes().FirstOrDefault(t => t.BaseType == typeof(GridJobModule));

            if (entryPoint == null)
            {
                throw new GridJobTaskCommandException(task, $"Unable to load module {link}: target module do not release {typeof(GridJobModule).FullName} class");
            }

            dynamic obj;

            try {
                obj = Activator.CreateInstance(entryPoint, null);
            } catch (Exception err) {
                throw new GridJobTaskCommandException(task, $"Unable to load module {link}: unable to create instance of {entryPoint.FullName} module entrypoint class", err);
            }

            return((GridJobModule)obj);
        }
示例#8
0
 public static bool CheckIfTaskDirectoriesExists(GridJobTask task)
 {
     return(Directory.Exists($"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}"));
 }
示例#9
0
 public static string ResolveFilePath(GridJobTask task, string fileName)
 {
     return($"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}\\{fileName}");
 }
示例#10
0
 public GridJobTaskCommandException(GridJobTask task, string msg, Exception err)
     : base(msg, err)
 {
     Task = task;
 }
示例#11
0
 public abstract void ExecuteTask(GridTaskExecutor executor, GridJobTask task, ILog logger);
示例#12
0
 public void WriteFileOutput(GridJobTask task, string outputFile, string text)
 {
     GridIo.StoreJobTaskOutputFile(task, outputFile, Encoding.UTF8.GetBytes(text));
 }
示例#13
0
 public void PrepareJobTaskDirectories(GridJobTask task)
 {
     GridIo.CreateDirectoriesForTask(task);
 }
示例#14
0
 public string ResolveFilePath(GridJobTask task, string fileName)
 {
     return(GridIo.ResolveFilePath(task, fileName));
 }
示例#15
0
 public string ResolveFilePath(GridJobTask task, GridJobFile file)
 {
     return(GridIo.ResolveFilePath(task.ParentJob, task, file));
 }