Skip to content

Commit

Permalink
Do not call state filter if job was not in Processing state
Browse files Browse the repository at this point in the history
  • Loading branch information
pieceofsummer committed Jun 11, 2017
1 parent fdbca4b commit 8e16449
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Hangfire.Console/States/ConsoleApplyStateFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction tran
return;
}

if (context.OldStateName != ProcessingState.StateName)
{
// Job was not in 'Processing' state, ignore.
return;
}

var jobDetails = context.Storage.GetMonitoringApi().JobDetails(context.BackgroundJob.Id);
if (jobDetails == null || jobDetails.History == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ public void DoesNotExpire_IfNotFollowsJobRetention()

stateChanger.ChangeState(context);

_monitoring.Verify(x => x.JobDetails(It.IsAny<string>()), Times.Never);
_transaction.Verify(x => x.ExpireSet(It.IsAny<string>(), It.IsAny<TimeSpan>()), Times.Never);
_transaction.Verify(x => x.ExpireHash(It.IsAny<string>(), It.IsAny<TimeSpan>()), Times.Never);
}

[Fact]
public void DoesNotExpire_IfOldStateWasNotProcessing()
{
_connection.Setup(x => x.GetJobData("1"))
.Returns(CreateJobData(EnqueuedState.StateName));
_monitoring.Setup(x => x.JobDetails("1"))
.Returns(CreateJobDetails());

var stateChanger = new BackgroundJobStateChanger(CreateJobFilterProvider());
var context = CreateStateChangeContext(new MockSucceededState());

stateChanger.ChangeState(context);

_monitoring.Verify(x => x.JobDetails(It.IsAny<string>()), Times.Never);
_transaction.Verify(x => x.ExpireSet(It.IsAny<string>(), It.IsAny<TimeSpan>()), Times.Never);
_transaction.Verify(x => x.ExpireHash(It.IsAny<string>(), It.IsAny<TimeSpan>()), Times.Never);
}
Expand Down

0 comments on commit 8e16449

Please sign in to comment.