public async static Task EndJob() { await Task.Delay(1000); IsJobRunning = false; JobEnded?.Invoke(nameof(EndJob)); }
private async Task Run(CancellationToken token) { // checking if it's supposed to run // it assumes that CalculateNextRun has been called previously from somewhere else if (!NextRun.HasValue) { return; } // calculating delay var delay = NextRun.Value - DateTime.Now; // delaying until it's time to run or a cancellation was requested await Task.Delay(delay < TimeSpan.Zero?TimeSpan.Zero : delay, token); // checking if a cancellation was requested if (token.IsCancellationRequested) { return; } // used on both JobStarted and JobEnded events var startTime = DateTime.Now; // raising JobStarted event JobStarted?.Invoke(this, new JobStartedEventArgs(startTime)); // used on JobEnded event Exception exception = null; try { // running the job _job(); } catch (Exception e) { // catching the exception if any exception = e; } // used on JobEnded event var endTime = DateTime.Now; // calculating the next run // used on both JobEnded event and for the next run of this method CalculateNextRun(startTime); // raising JobEnded event JobEnded?.Invoke(this, new JobEndedEventArgs(exception, startTime, endTime, NextRun)); // recursive call // note that the NextRun was already calculated in this run _task = Run(token); }
public JobExecutionResult ExecuteJob(int jobIndex) { if (jobIndex < 0 || jobIndex >= Jobs.Length) { var result = JobExecutionResult.CreateJobNotFound(); JobEnded?.Invoke(this, new JobEndedEventArgs(null, result)); return(result); } return(ExecuteJob(Jobs[jobIndex])); }
private async Task Worker(string setedTime) { await Task.Run(() => { TimeChecker(setedTime); pageSettings = new MainPageSettings(); pageSettings.PageWorker(); appsOpener = new AppsOpener(); appsOpener.OpenApps(); JobEnded?.Invoke(); }); }
public JobExecutionResult ExecuteJob(MatrixJob job) { JobStarting?.Invoke(this, new JobStartingEventArgs(job)); var executionContext = new ExecutionContext( job, buildConfiguration, engineConfiguration.Outputter, engineConfiguration.RepositoryDirectoryPath, !string.IsNullOrEmpty(buildConfiguration.CloneFolder) ? buildConfiguration.CloneFolder : new ExpandableString(@"C:\Projects\LocalAppVeyorTempClone")); JobExecutionResult executionResult; try { var isSuccess = ExecuteBuildPipeline(executionContext); // on_success / on_failure only happen here, after we know the build status // they do intervene on build final status though isSuccess = isSuccess ? new OnSuccessStep(engineConfiguration.FileSystem, executionContext.CloneDirectory, buildConfiguration.OnSuccessScript).Execute(executionContext) : new OnFailureStep(engineConfiguration.FileSystem, executionContext.CloneDirectory, buildConfiguration.OnFailureScript).Execute(executionContext); return(isSuccess ? JobExecutionResult.CreateSuccess() : JobExecutionResult.CreateFailure()); } catch (SolutionNotFoundException) { executionResult = JobExecutionResult.CreateSolutionNotFound(); } catch (Exception e) { executionResult = JobExecutionResult.CreateUnhandledException(e); } finally { // on_finish don't influence build final status so we just run it new OnFinishStep(engineConfiguration.FileSystem, executionContext.CloneDirectory, buildConfiguration.OnFinishScript).Execute(executionContext); } JobEnded?.Invoke(this, new JobEndedEventArgs(job, executionResult)); return(executionResult); }
public JobExecutionResult ExecuteJob(MatrixJob job) { JobStarting?.Invoke(this, new JobStartingEventArgs(job)); var executionContext = new ExecutionContext( job, _buildConfiguration, _engineConfiguration.Outputter, _engineConfiguration.RepositoryDirectoryPath, !string.IsNullOrEmpty(_buildConfiguration.CloneFolder) ? _buildConfiguration.CloneFolder : new ExpandableString(_engineConfiguration.FallbackCloneDirectoryPath), _engineConfiguration.FileSystem); var executionResult = new BuildPipelineExecuter(executionContext).Execute(); JobEnded?.Invoke(this, new JobEndedEventArgs(job, executionResult)); return(executionResult); }