public static Task Run(TaskType taskType) { var type = GetTaskType(taskType); var pidFilename = PidFileHelper.GetPidFileName(type); using (var pidFile = new PidFileContext(pidFilename)) { var task = (CliTask)ServiceLocator.Resolve(type); return(task.Run()); } }
public void CreatePidFileForCurrentProcess(string filename) { if (PidFileHelper.IsTaskRunning(filename, out var pid)) { throw new InvalidOperationException($"Process is already running (PID {pid}, PID file {filename})"); } using (var currentProcess = Process.GetCurrentProcess()) { File.WriteAllText(filename, currentProcess.Id.ToString()); } }
public static PidFileContext For(Type taskType) { return(new PidFileContext(PidFileHelper.GetPidFileName(taskType))); }