예제 #1
0
파일: TaskRunner.cs 프로젝트: topalach/demo
        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());
            }
        }
예제 #2
0
        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());
            }
        }
예제 #3
0
 public static PidFileContext For(Type taskType)
 {
     return(new PidFileContext(PidFileHelper.GetPidFileName(taskType)));
 }