public void ToString_ShouldBeDescriptiveForRunning() { var status = JobRunStatus.Create("do something").ToRunningState(StartTime); status.ToString() .Should() .Be($"Task {status.Description} ({status.Id}) - Running for {(int)status.Duration.Value.TotalSeconds} seconds"); }
public JobRunStatus WaitForTaskToComplete(JobRunStatus status) { Waited = true; return(new JobRunStatus() { Result = Result.Successful() }); }
public void ToString_ShouldBeDescriptiveForFinished() { var status = JobRunStatus.Create("do something") .ToRunningState(StartTime) .ToFinishedState(Result.Failure("failed!"), StartTime.Add(TimeSpan.FromSeconds(5))); status.ToString().Should().Be($"Task {status.Description} ({status.Id}) - {status.Result}"); }
public void Duration_ShouldBeBasedOnCurrentDate() { var status = JobRunStatus.Create("do something") .ToRunningState(DateTime.Now.Subtract(TimeSpan.FromMinutes(1))); status.Duration.HasValue.Should().BeTrue("because the task has started"); status.Duration.Value.TotalSeconds.Should().BeGreaterOrEqualTo(60); }
public void Duration_ShouldBeBasedOnStartAndCompleteDate() { var status = JobRunStatus.Create("do something") .ToRunningState(StartTime) .ToFinishedState(Result.Successful(), StartTime.AddMinutes(2)); status.Duration.HasValue.Should().BeTrue("because the task has finished"); status.Duration.Value.TotalSeconds.Should().Be(120); }
protected override JobRunStatus ProcessFailurePaging(ExecutionFailures failures, JobPagingInfo pagingInfo) { var remainingFailed = DeleteSuccessfulFailed(failures); var status = new JobRunStatus(); if (IsNoRetry()) { if (IsSubJob()) { var parentId = Job.ParentJob.Value; AssociateFailedToParent(remainingFailed); if (IsWaitingOnSubJobs(Service, parentId)) { if (Job.IgnoreFailure == true) { Log.Log($"Updating paging info of job, page {pagingInfo.NextPage} ..."); UpdatePaging(Service, parentId, pagingInfo); Log.Log($"Updated paging info of job, page {pagingInfo.NextPage}."); Log.Log($"Updating status of job parent '{parentId}' to 'waiting' ..."); SetStatus(Service, CustomJob.StatusReasonEnum.Waiting, parentId, IsParentRecurrentJob()); Log.Log($"Updated status of job parent '{parentId}' to 'waiting'."); } else { Log.Log($"Updating status of job parent '{parentId}' to 'failed' ..."); Close(Service, CustomJob.StatusReasonEnum.Failure, Job.ParentJob.Value, true); Log.Log($"Updated status of job parent '{parentId}' to 'failed'."); } } } status.IsClose = true; } else { if (Job.RetrySchedule != null) { UpdateRetryTargetDate(Service, Job, Log); } IncrementRetry(Job.CurrentRetryRun ?? 0); Log.Log($"Updating status of job to 'retry' ..."); SetStatus(Service, CustomJob.StatusReasonEnum.Retry, Job.Id, false); Log.Log($"Updated status of job 'retry'."); } status.IsSuccess = false; status.LatestRunMessage = $"Retry run failed."; return(status); }
public void BeginPresenting(JobRunStatus status) { if (status == null) { throw new ArgumentNullException(nameof(status)); } _lastStatus = status; if (status.IsNotRun) { _messagePresenter.ShowMessage($"Server waiting to start {status.Description}"); } }
public void NullStatus_ShouldBeIgnored() { var presenter = new FakeMessagePresenter(); var statusPresenter = new JobRunStatusPresenter(presenter); statusPresenter.BeginPresenting(JobRunStatus.Create("task")); presenter.Clear(); statusPresenter.PresentAnyChangesTo(null); presenter.WasMessageShown.Should().BeFalse("because nothing was given to the status presenter"); }
public void SameMessage_ShouldNotLogAnything() { var presenter = new FakeMessagePresenter(); var status = JobRunStatus.Create("task"); var statusPresenter = new JobRunStatusPresenter(presenter); statusPresenter.BeginPresenting(status); presenter.Clear(); statusPresenter.PresentAnyChangesTo(status); presenter.WasMessageShown.Should().BeFalse("because no changes have been made yet"); }
public void MessageChange_ShouldLogMessageAfterFirstTime() { var presenter = new FakeMessagePresenter(); var status = JobRunStatus.Create("task"); var statusPresenter = new JobRunStatusPresenter(presenter); statusPresenter.BeginPresenting(status); statusPresenter.PresentAnyChangesTo(status.WithDifferentMessage("another")); presenter.Clear(); statusPresenter.PresentAnyChangesTo(status.WithDifferentMessage("third")); presenter.WasMessageShown.Should().BeTrue("because the message changed"); }
public void TaskStart_ShouldLogMessage() { var presenter = new FakeMessagePresenter(); var status = JobRunStatus.Create("task"); var statusPresenter = new JobRunStatusPresenter(presenter); statusPresenter.BeginPresenting(status); presenter.Clear(); var copy = status.ToRunningState(StartTime); statusPresenter.PresentAnyChangesTo(copy); presenter.WasMessageShown.Should().BeTrue("because the task started"); }
public void Copy_ShouldCopyCurrentMessageIndex() { var status = JobRunStatus.Create("with message index"); status.CurrentMessage = "great times"; status.CurrentMessageIndex = 22; status.PreviousMessageIndex = 20; status.Messages = new[] { "good times", "great times" }; var copy = status.Copy(); copy.CurrentMessageIndex.Should().Be(22); copy.PreviousMessageIndex.Should().Be(20); copy.Messages.Length.Should().Be(2); copy.Messages[0].Should().Be("good times"); copy.Messages[1].Should().Be("great times"); }
public void TwoMessagesInARow_ShouldNotBePresented() { var presenter = new FakeMessagePresenter(); var status = JobRunStatus.Create("task"); var statusPresenter = new JobRunStatusPresenter(presenter); statusPresenter.BeginPresenting(status); var another = status.WithDifferentMessage("another"); statusPresenter.PresentAnyChangesTo(another); presenter.Clear(); statusPresenter.PresentAnyChangesTo(another); presenter.WasMessageShown.Should().BeFalse("because the message did not change"); }
internal JobRunInfoBuilder( int runIndex, JobStartReason startReason, DateTimeOffset dueTime, bool dueTimeWasOverridden, DateTimeOffset startTime, JobRunStatus status, StringWriter outputWriter) { this.RunIndex = runIndex; this.StartReason = startReason; this.DueTime = dueTime; this.DueTimeWasOverridden = dueTimeWasOverridden; this.StartTime = startTime; this.Status = status; this.OutputWriter = outputWriter; }
public void DifferentCurrentMessage_ShouldLogMessage() { var presenter = new FakeMessagePresenter(); var status = JobRunStatus.Create("task"); var statusPresenter = new JobRunStatusPresenter(presenter); statusPresenter.BeginPresenting(status); presenter.Clear(); var copy = status.ToRunningState(StartTime); copy.CurrentMessage = "different message"; statusPresenter.PresentAnyChangesTo(copy); presenter.WasMessageShown.Should().BeTrue("because the message changed"); presenter.MessageShown.Should().Be($"Latest: {copy.CurrentMessage}"); }
public void PresentAnyChangesTo(JobRunStatus status) { if (status == null) { return; } if (_lastStatus == null) { throw new InvalidOperationException("Expecting last status to be populated"); } if (_lastStatus.IsNotRun && status.IsRunning) { _messagePresenter.ShowMessage($"Server started running {status.Description} at {status.StartTime}"); } if (!string.Equals(_lastStatus.CurrentMessage, status.CurrentMessage)) { _messagePresenter.ShowMessage($"Latest: {status.CurrentMessage}"); } _lastStatus = status; }
public void Exception_ShouldSetAutoresetEventAndFail() { var jobServer = new Mock <IJobServer>(); jobServer.Setup(s => s.GetJobRunStatus(It.IsAny <Guid>(), It.IsAny <int>())).Throws <HttpRequestException>(); var autoResetEvent = new FakeAutoResetEvent(); var fakeTimerFactory = new FakeTimerFactory(); var waiter = new SchedulerWaiter(() => jobServer.Object, autoResetEvent, fakeTimerFactory, new FakeMessagePresenter()); autoResetEvent.WhatToDoDuringWaitOne = () => { fakeTimerFactory.FireTimerAction(); }; var result = waiter.WaitForTaskToComplete(JobRunStatus.Create("sample task")); result.Result.IsSuccess.Should().BeFalse("because an exception was thrown by the scheduler"); result.Result.FailureDescription.Should() .NotBeEmpty("because it should contain a description of what happened"); }
public JobRunInfo( int runIndex, JobStartReason startReason, DateTimeOffset dueTime, bool dueTimeWasOverridden, DateTimeOffset startTime, DateTimeOffset?endTime, JobRunStatus status, string output, Exception exception) { // todo checks: positive etc // todo date is valid this.RunIndex = runIndex; this.StartReason = startReason; this.DueTime = dueTime; this.DueTimeWasOverridden = dueTimeWasOverridden; this.StartTime = startTime; this.EndTime = endTime; this.Status = status; this.Output = output; this.Exception = exception; }
protected override JobRunStatus ProcessFailurePaging(ExecutionFailures failures, JobPagingInfo pagingInfo) { List <CustomJobFailedTarget> newFailures; var status = new JobRunStatus(); if (IsNoRetry()) { newFailures = AssociateFailedTargets(failures, Job.Id); if (Job.FailureAction != null) { log.Log("Running failure action ..."); try { Service.Execute( new ExecuteWorkflowRequest { EntityId = Job.Id, WorkflowId = Job.FailureAction.Value }); } catch (Exception exception) { log.Log(exception); } log.Log("Finished running failure action."); } if (Job.IgnoreFailure == true) { status = ProcessSuccessPaging(pagingInfo); status.RunTargetFailures = newFailures; if (IsSubJob()) { status.ParentId = Job.ParentJob.Value; } return(status); } if (IsSubJob()) { var parentId = Job.ParentJob.Value; if (IsWaitingOnSubJobs(Service, parentId)) { log.Log($"Updating status of job parent '{parentId}' to 'failed' ..."); Close(Service, CustomJob.StatusReasonEnum.Failure, parentId, true); log.Log($"Updated status of job parent '{parentId}' to 'failed'."); } status.ParentId = parentId; } status.IsClose = true; } else { log.Log($"Creating a retry sub-job ..."); var extendingJob = BuildSubJob(Job, CustomJob.StatusReasonEnum.Retry, $"Retry Page {Job.PageNumber ?? 1}"); extendingJob.CurrentRetryRun = 1; extendingJob.Id = Service.Create(extendingJob); log.Log($"Created a retry sub-job '{extendingJob.Name}'."); newFailures = AssociateFailedTargets(failures, extendingJob.Id); log.Log($"Updating status of job 'waiting on subs' ..."); SetStatus(Service, CustomJob.StatusReasonEnum.WaitingOnSubJobs, Job.Id, false); log.Log($"Updating status of job 'waiting on subs'."); } status.IsSuccess = false; status.LatestRunMessage = $"Page {Job.PageNumber} failed."; status.RunTargetFailures = newFailures; return(status); }
public void Duration_ShouldBeNullBeforeRunning() { var status = JobRunStatus.Create("do something"); status.Duration.Should().BeNull("because it hasn't yet started"); }
private void SaveJobAndJobRun(JobRunContext jobContext, RetryPolicy retryPolicy, JobRunStatus status, Exception exception = null) { var session = jobContext.OperationContext.OpenSession(); var job = NewJob(session, jobContext.JobName, jobContext.StartInfo, retryPolicy); job.Id = jobContext.JobId; var jobRun = NewJobRun(job, JobRunType.Immediate); jobRun.Id = jobContext.JobRunId; jobContext.IsPersisted = true; jobRun.Status = status; jobRun.StartedOn = jobContext.StartedOn; if (exception != null) { UpdateFailedJobRun(session, jobRun, jobContext, exception); } session.SaveChanges(); }
public void ToString_ShouldBeDescriptiveForNotRun() { var status = JobRunStatus.Create("do something"); status.ToString().Should().Be($"Task {status.Description} ({status.Id}) - Not yet run"); }