/// <summary> /// Initializes a new instance of the <see cref="JobRunContext"/> class. /// </summary> public JobRunContext(JobRunInfo jobRunInfoIfo, ForkedExecutionConfiguration configuration, IJobRunProgressChannel progressChannel) { this.jobRunInfo = jobRunInfoIfo; this.configuration = configuration; this.progressChannel = progressChannel; this.serviceMessageParser = new ServiceMessageParser(); }
internal void Finish(JobRunInfo finalRunInfo) { lock (_lock) { _list.Add(finalRunInfo); _currentRun = null; } }
public IJobRunContext CreateJobRunContext(JobRunInfo jobRunInfo) { var mockedJobContext = new MockedJobContext(jobRunInfo, this.progressChannel); this.contexts.Add(mockedJobContext); return(mockedJobContext); }
internal void Start(JobRunInfo initialRunInfo) { // todo: check _currentRun == null (log if not?) lock (_lock) { _currentRun = initialRunInfo; } }
private string SetupDirectories(JobRunInfo jobRun) { // Create the WorkingDir and TempDir for the execution var jobRunPath = Path.Combine(this.configuration.JobRunDirectory, "jobbr-" + jobRun.Id); Logger.Info($"[{jobRun.Id}] Preparing filesytem directories in '{this.configuration.JobRunDirectory}'"); var tempDir = Path.Combine(jobRunPath, "temp"); var workDir = Path.Combine(jobRunPath, "work"); Directory.CreateDirectory(tempDir); Logger.Info($"[{jobRun.Id}] Created Temp-Directory '{tempDir}'"); Directory.CreateDirectory(workDir); Logger.Info($"[{jobRun.Id}] Created Working-Directory '{workDir}'"); return(workDir); }
public JobRunInfo GetByJobRunId(long jobRunId) { Logger.Debug($"Retrieving information regarding jobrun with id '{jobRunId}'"); var jobRun = this.jobbrRepository.GetJobRunById(jobRunId); if (jobRun == null) { return(null); } var trigger = this.jobbrRepository.GetTriggerById(jobRun.Job.Id, jobRun.Trigger.Id); var job = this.jobbrRepository.GetJob(jobRun.Job.Id); var info = new JobRunInfo(); this.mapper.Map(job, info); this.mapper.Map(trigger, info); this.mapper.Map(jobRun, info); return(info); }
private void StartProcess(JobRunInfo jobRun, string workDir) { var runnerFileExe = Path.GetFullPath(this.configuration.JobRunnerExecutable); Logger.Info($"[{jobRun.Id}] Preparing to start the runner from '{runnerFileExe}' in '{workDir}'"); var proc = new Process { EnableRaisingEvents = true, StartInfo = { FileName = runnerFileExe } }; var arguments = $"--jobRunId {jobRun.Id} --server {this.configuration.BackendAddress}"; if (this.configuration.IsRuntimeWaitingForDebugger) { arguments += " --debug"; } if (this.configuration.AddJobRunnerArguments != null) { var model = new JobRunStartInfo { JobType = jobRun.Type, UniqueName = jobRun.UniqueName, JobRunId = jobRun.Id, JobId = jobRun.JobId, TriggerId = jobRun.TriggerId, UserId = jobRun.UserId }; var additionalArguments = this.configuration.AddJobRunnerArguments(model); foreach (var additionalArgument in additionalArguments) { if (additionalArgument.Value.Contains(" ")) { arguments += $" --{additionalArgument.Key} \"{additionalArgument.Value}\""; } else { arguments += $" --{additionalArgument.Key} {additionalArgument.Value}"; } } } proc.StartInfo.Arguments = arguments; proc.StartInfo.WorkingDirectory = workDir; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; // Wire events proc.OutputDataReceived += this.ProcOnOutputDataReceived; proc.Exited += (o, args) => this.OnEnded(new JobRunEndedEventArgs() { ExitCode = proc.ExitCode, JobRun = jobRun, ProcInfo = proc, DidReportProgress = this.didReportProgress }); this.progressChannel.PublishStatusUpdate(this.jobRunInfo.Id, JobRunStates.Starting); Logger.Info($"[{jobRun.Id}] Starting '{runnerFileExe} {arguments}' in '{workDir}'"); proc.Start(); Logger.Info($"[{jobRun.Id}] Started Runner with ProcessId '{proc.Id}' at '{proc.StartTime}'"); this.progressChannel.PublishPid(jobRun.Id, proc.Id, Environment.MachineName); proc.BeginOutputReadLine(); }
public MockedJobContext(JobRunInfo jobRunInfo, IJobRunProgressChannel progressChannel) { this.jobRunInfo = jobRunInfo; this.progressChannel = progressChannel; }
public IJobRunContext CreateJobRunContext(JobRunInfo jobRunInfo) { return(new JobRunContext(jobRunInfo, this.configuration, this.progressChannel)); }