AwaitBatch BackgroundJob not moving past Created

sql-server
Tags: #<Tag:0x00007f281a9ee848>

#1

Hello All,

We are encountering a bit of an odd situation and I just want to validate my assumptions.

We have some code:

var batchJobId = BatchJob.StartNew(x =>
	{
		var job1Id = x.Enqueue<Coordinator>(c => c.DoStuff1());
		if (someCondition)
		{
			x.ContinueWith<Coordinator>(job1Id, boc => boc.DoStuff2(), JobContinuationOptions.OnlyOnSucceededState);
		}
	});
BatchJob.AwaitBatch(batchJobId, x => x.Enqueue<Coordinator>(boc => boc.DoStuff3()), null, BatchContinuationOptions.OnAnyFinishedState);

We’ve noticed that DoStuff() and DoStuff2() both executed successfully, but DoStuff3() (in the AwaitBatch) was never executed. (This code generally works just fine in multiple environments, so this case was a bit odd). Upon further investigation, we discovered that the enqueue for DoStuff3() didn’t appear to have saved in the database until after DoStuff2() executed (we are working to address this issue separately) and it looks like that may have been the reason DoStuff3() was never enqueued?

However, my assumption was that calling AwaitBatch for a Batch with Jobs that are already completed should be ok. Is that assumption wrong, am I doing something odd or have I discovered a bug/race condition?

Our short-term fix is to move the DoStuff3 into the BatchJob.StartNew call as the AwaitBatch code is a bit redundant for what we’re doing. We’re also standing up a db in the same data-center as these servers to help mitigate the SQL latency.

Finally, is there a functional difference between BatchJob.AwaitBatch and BatchJob.AwaitJob that I should be aware of?

Thanks in advance!