Skip to content

Commit 246beb2

Browse files
committed
TaskScheduler should handle multi-server environments better
1 parent 2c0576b commit 246beb2

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/Presentation/SmartStore.Web/Controllers/TaskSchedulerController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public ActionResult Sweep()
4444
var prevTaskStart = DateTime.UtcNow;
4545
var count = 0;
4646

47-
foreach (var task in pendingTasks)
47+
for (var i = 0; i < pendingTasks.Count; i++)
4848
{
49-
var elapsedSincePrevTask = DateTime.UtcNow - prevTaskStart;
50-
if (elapsedSincePrevTask >= TimeSpan.FromMinutes(_taskScheduler.SweepIntervalMinutes))
49+
var task = pendingTasks[i];
50+
51+
if (i > 0)
5152
{
52-
// the previous Task execution in this loop took longer
53-
// than the scheduler's sweep interval. Most likely a subsequent
54-
// Sweep call executed it already in another HTTP request.
53+
// Maybe a subsequent Sweep call or another machine in a webfarm executed
54+
// successive tasks already.
5555
// To be able to determine this, we need to reload the entity from the database.
5656
// The TaskExecutor will exit when the task should be in running state then.
5757
_services.DbContext.ReloadEntity(task);

0 commit comments

Comments
 (0)