diff --git a/Duplicati/Server/Scheduler.cs b/Duplicati/Server/Scheduler.cs index 5ec0a28f1..c496761fd 100644 --- a/Duplicati/Server/Scheduler.cs +++ b/Duplicati/Server/Scheduler.cs @@ -81,6 +81,7 @@ namespace Duplicati.Server m_thread = new Thread(new ThreadStart(Runner)); m_worker = worker; m_worker.CompletedWork += OnCompleted; + m_worker.StartingWork += OnStartingWork; m_schedule = new KeyValuePair[0]; m_terminate = false; m_event = new AutoResetEvent(false); @@ -211,7 +212,25 @@ namespace Duplicati.Server } } - + + private void OnStartingWork(WorkerThread worker, Runner.IRunnerData task) + { + if (task is null) + { + return; + } + + lock(m_lock) + { + if (m_updateTasks.TryGetValue(task, out Tuple scheduleInfo)) + { + // Item2 is the scheduled start time (Time in the Schedule table). + // Item3 is the actual start time (LastRun in the Schedule table). + m_updateTasks[task] = Tuple.Create(scheduleInfo.Item1, scheduleInfo.Item2, DateTime.UtcNow); + } + } + } + /// /// The actual scheduling procedure /// @@ -308,10 +327,15 @@ namespace Duplicati.Server Server.Runner.IRunnerData lastJob = jobsToRun.LastOrDefault(); if (lastJob != null) - lock(m_lock) + { + lock (m_lock) + { + // The actual last run time will be updated when the StartingWork event is raised. m_updateTasks[lastJob] = new Tuple(sc, start, DateTime.UtcNow); - - foreach(var job in jobsToRun) + } + } + + foreach (var job in jobsToRun) m_worker.AddTask(job); if (start < DateTime.UtcNow)