"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Duplicati/Server/Scheduler.cs" between
duplicati-2.0.5.104-2.0.5.104_canary_2020-03-25.tar.gz and duplicati-2.0.5.106-2.0.5.106_canary_2020-05-11.tar.gz

About: Duplicati is a backup client that securely stores encrypted, incremental, compressed backups on local devices, cloud storage services and remote file servers (for Windows, macOS and Linux). A remark: This officially "pre-release" seems to run stable.

Scheduler.cs  (duplicati-2.0.5.104-2.0.5.104_canary_2020-03-25):Scheduler.cs  (duplicati-2.0.5.106-2.0.5.106_canary_2020-05-11)
skipping to change at line 83 skipping to change at line 83
/// <summary> /// <summary>
/// Constructs a new scheduler /// Constructs a new scheduler
/// </summary> /// </summary>
/// <param name="worker">The worker thread</param> /// <param name="worker">The worker thread</param>
public Scheduler(WorkerThread<Server.Runner.IRunnerData> worker) public Scheduler(WorkerThread<Server.Runner.IRunnerData> worker)
{ {
m_thread = new Thread(new ThreadStart(Runner)); m_thread = new Thread(new ThreadStart(Runner));
m_worker = worker; m_worker = worker;
m_worker.CompletedWork += OnCompleted; m_worker.CompletedWork += OnCompleted;
m_worker.StartingWork += OnStartingWork;
m_schedule = new KeyValuePair<DateTime, ISchedule>[0]; m_schedule = new KeyValuePair<DateTime, ISchedule>[0];
m_terminate = false; m_terminate = false;
m_event = new AutoResetEvent(false); m_event = new AutoResetEvent(false);
m_updateTasks = new Dictionary<Server.Runner.IRunnerData, Tuple<ISch edule, DateTime, DateTime>>(); m_updateTasks = new Dictionary<Server.Runner.IRunnerData, Tuple<ISch edule, DateTime, DateTime>>();
m_thread.IsBackground = true; m_thread.IsBackground = true;
m_thread.Name = "TaskScheduler"; m_thread.Name = "TaskScheduler";
m_thread.Start(); m_thread.Start();
} }
/// <summary> /// <summary>
skipping to change at line 176 skipping to change at line 177
res = res.AddDays(1); res = res.AddDays(1);
} }
else else
{ {
// We jump less than a day, so we keep adding the repetition until // We jump less than a day, so we keep adding the repetition until
// we hit a valid day // we hit a valid day
i = 50000; i = 50000;
while (!IsDateAllowed(res, allowedDays) && i-- > 0) while (!IsDateAllowed(res, allowedDays) && i-- > 0)
res = Timeparser.ParseTimeInterval(repetition, res); res = Timeparser.ParseTimeInterval(repetition, res);
} }
} }
if (!IsDateAllowed(res, allowedDays) || res < firstdate) if (!IsDateAllowed(res, allowedDays) || res < firstdate)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (allowedDays != null) if (allowedDays != null)
foreach (DayOfWeek w in allowedDays) foreach (DayOfWeek w in allowedDays)
{ {
if (sb.Length != 0) if (sb.Length != 0)
sb.Append(", "); sb.Append(", ");
skipping to change at line 214 skipping to change at line 215
if (t != null) if (t != null)
{ {
t.Item1.Time = t.Item2; t.Item1.Time = t.Item2;
t.Item1.LastRun = t.Item3; t.Item1.LastRun = t.Item3;
Program.DataConnection.AddOrUpdateSchedule(t.Item1); Program.DataConnection.AddOrUpdateSchedule(t.Item1);
} }
} }
private void OnStartingWork(WorkerThread<Runner.IRunnerData> worker, Run
ner.IRunnerData task)
{
if (task is null)
{
return;
}
lock(m_lock)
{
if (m_updateTasks.TryGetValue(task, out Tuple<ISchedule, DateTim
e, DateTime> scheduleInfo))
{
// Item2 is the scheduled start time (Time in the Schedule t
able).
// Item3 is the actual start time (LastRun in the Schedule t
able).
m_updateTasks[task] = Tuple.Create(scheduleInfo.Item1, sched
uleInfo.Item2, DateTime.UtcNow);
}
}
}
/// <summary> /// <summary>
/// The actual scheduling procedure /// The actual scheduling procedure
/// </summary> /// </summary>
private void Runner() private void Runner()
{ {
var scheduled = new Dictionary<long, KeyValuePair<long, DateTime>>() ; var scheduled = new Dictionary<long, KeyValuePair<long, DateTime>>() ;
while (!m_terminate) while (!m_terminate)
{ {
//TODO: As this is executed repeatedly we should cache it //TODO: As this is executed repeatedly we should cache it
// to avoid frequent db lookups // to avoid frequent db lookups
skipping to change at line 275 skipping to change at line 294
var jobsToRun = new List<Server.Runner.IRunnerData>( ); var jobsToRun = new List<Server.Runner.IRunnerData>( );
//TODO: Cache this to avoid frequent lookups //TODO: Cache this to avoid frequent lookups
foreach(var id in Program.DataConnection.GetBackupID sForTags(sc.Tags).Distinct().Select(x => x.ToString())) foreach(var id in Program.DataConnection.GetBackupID sForTags(sc.Tags).Distinct().Select(x => x.ToString()))
{ {
//See if it is already queued //See if it is already queued
var tmplst = from n in m_worker.CurrentTasks var tmplst = from n in m_worker.CurrentTasks
where n.Operation == Duplicati.Server.Se rialization.DuplicatiOperation.Backup where n.Operation == Duplicati.Server.Se rialization.DuplicatiOperation.Backup
select n.Backup; select n.Backup;
var tastTemp = m_worker.CurrentTask; var tastTemp = m_worker.CurrentTask;
if (tastTemp != null && tastTemp.Operation == Du plicati.Server.Serialization.DuplicatiOperation.Backup) if (tastTemp != null && tastTemp.Operation == Du plicati.Server.Serialization.DuplicatiOperation.Backup)
tmplst.Union(new [] { tastTemp.Backup }); tmplst = tmplst.Union(new [] { tastTemp.Back up });
//If it is not already in queue, put it there //If it is not already in queue, put it there
if (!tmplst.Any(x => x.ID == id)) if (!tmplst.Any(x => x.ID == id))
{ {
var entry = Program.DataConnection.GetBackup (id); var entry = Program.DataConnection.GetBackup (id);
if (entry != null) if (entry != null)
{ {
Dictionary<string, string> options = Dup licati.Server.Runner.GetCommonOptions(); Dictionary<string, string> options = Dup licati.Server.Runner.GetCommonOptions();
Duplicati.Server.Runner.ApplyOptions(ent ry, options); Duplicati.Server.Runner.ApplyOptions(ent ry, options);
if ((new Duplicati.Library.Main.Options( options)).DisableOnBattery && (Duplicati.Library.Utility.Power.PowerSupply.GetSo urce() == Duplicati.Library.Utility.Power.PowerSupply.Source.Battery)) if ((new Duplicati.Library.Main.Options( options)).DisableOnBattery && (Duplicati.Library.Utility.Power.PowerSupply.GetSo urce() == Duplicati.Library.Utility.Power.PowerSupply.Source.Battery))
skipping to change at line 310 skipping to change at line 329
start = GetNextValidTime(start, new DateTime(Mat h.Max(DateTime.UtcNow.AddSeconds(1).Ticks, start.AddSeconds(1).Ticks), DateTimeK ind.Utc), sc.Repeat, sc.AllowedDays); start = GetNextValidTime(start, new DateTime(Mat h.Max(DateTime.UtcNow.AddSeconds(1).Ticks, start.AddSeconds(1).Ticks), DateTimeK ind.Utc), sc.Repeat, sc.AllowedDays);
} }
catch(Exception ex) catch(Exception ex)
{ {
Program.DataConnection.LogError(sc.ID.ToString() , "Scheduler failed to find next date", ex); Program.DataConnection.LogError(sc.ID.ToString() , "Scheduler failed to find next date", ex);
continue; continue;
} }
Server.Runner.IRunnerData lastJob = jobsToRun.LastOr Default(); Server.Runner.IRunnerData lastJob = jobsToRun.LastOr Default();
if (lastJob != null) 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<ISchedule , DateTime, DateTime>(sc, start, DateTime.UtcNow); m_updateTasks[lastJob] = new Tuple<ISchedule , DateTime, DateTime>(sc, start, DateTime.UtcNow);
}
}
foreach(var job in jobsToRun) foreach (var job in jobsToRun)
m_worker.AddTask(job); m_worker.AddTask(job);
if (start < DateTime.UtcNow) if (start < DateTime.UtcNow)
{ {
//TODO: Report this somehow //TODO: Report this somehow
continue; continue;
} }
} }
scheduled[sc.ID] = new KeyValuePair<long,DateTime>(sctic ks, start); scheduled[sc.ID] = new KeyValuePair<long,DateTime>(sctic ks, start);
 End of changes. 7 change blocks. 
4 lines changed or deleted 34 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)