1
0
mirror of https://github.com/Kopano-dev/kopano-ol-extension.git synced 2023-10-10 13:37:40 +02:00

[KOE-104] Added PeriodThrottle property to ZPush sync tasks, to throttle the number of requests to the server. Defaults to 15 minutes, meaning the server will not be contacted more than once every 15 minutes.

This commit is contained in:
Patrick Simpson 2017-05-17 10:10:58 +02:00
parent 0a14071da1
commit d7185cdbcf
4 changed files with 53 additions and 6 deletions

View File

@ -102,8 +102,16 @@ namespace Acacia
public const string DATE_ISO_8601 = "yyyyMMddTHHmmssZ";
/// <summary>
/// Default period for synchronisation tasks
/// </summary>
public static readonly TimeSpan ZPUSH_SYNC_DEFAULT_PERIOD = new TimeSpan(1, 0, 0);
/// <summary>
/// Default period during which synchronisation tasks will not be executed again.
/// </summary>
public static readonly TimeSpan ZPUSH_SYNC_DEFAULT_PERIOD_THROTTLE = new TimeSpan(0, 15, 0);
#region Registry
public const string PLUGIN_REGISTRY_BASE = "Software\\" + PRODUCT_PREFIX + "\\" + PRODUCT_NAME;

View File

@ -194,6 +194,16 @@ namespace Acacia.Features.DebugSupport
{
get { return ThisAddIn.Instance.Watcher.Sync.Period; }
}
[DebugCategory(DebugCategory.Misc)]
public TimeSpan ZPushSyncPeriodThrottle
{
get { return ThisAddIn.Instance.Watcher.Sync.PeriodThrottle; }
}
[DebugCategory(DebugCategory.Misc)]
public DateTime ZPushSyncLast
{
get { return ThisAddIn.Instance.Watcher.Sync.LastSyncTime; }
}
[DebugCategory(DebugCategory.Misc)]
public string Build

View File

@ -90,6 +90,14 @@ namespace Acacia
}
private static readonly TimeSpanOption ZPUSH_SYNC_PERIOD = new TimeSpanOption("ZPushSyncPeriod", Constants.ZPUSH_SYNC_DEFAULT_PERIOD);
[AcaciaOption("Sets the interval during which ZPush synchronization tasks will be not executed to prevent overloading the server.")]
public TimeSpan ZPushSync_PeriodThrottle
{
get { return GetOption(null, ZPUSH_SYNC_PERIOD_THROTTLE); }
set { SetOption(null, ZPUSH_SYNC_PERIOD_THROTTLE, value); }
}
private static readonly TimeSpanOption ZPUSH_SYNC_PERIOD_THROTTLE = new TimeSpanOption("ZPushSyncPeriodThrottle", Constants.ZPUSH_SYNC_DEFAULT_PERIOD_THROTTLE);
[AcaciaOption("Disables the release of COM objects. This generally leads to resource leaks and should " +
"only be disabled for debug purposes.")]
public bool COMRelease

View File

@ -1,4 +1,4 @@
/// Copyright 2016 Kopano b.v.
/// Copyright 2017 Kopano b.v.
///
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License, version 3,
@ -28,7 +28,7 @@ using System.Windows.Forms;
namespace Acacia.ZPush
{
/// <summary>
/// Helper for synchronising state with ZPush servers
/// Helper for periodically synchronising state with ZPush servers
/// </summary>
public class ZPushSync : DisposableWrapper
{
@ -85,6 +85,8 @@ namespace Acacia.ZPush
public readonly bool Enabled;
public readonly TimeSpan Period;
public readonly TimeSpan PeriodThrottle;
public DateTime LastSyncTime;
public ZPushSync(ZPushWatcher watcher, IAddIn addIn)
{
@ -93,6 +95,9 @@ namespace Acacia.ZPush
Period = GlobalOptions.INSTANCE.ZPushSync_Period;
if (Period.Ticks == 0)
Period = Constants.ZPUSH_SYNC_DEFAULT_PERIOD;
PeriodThrottle = GlobalOptions.INSTANCE.ZPushSync_PeriodThrottle;
if (PeriodThrottle.Ticks == 0)
PeriodThrottle = Constants.ZPUSH_SYNC_DEFAULT_PERIOD_THROTTLE;
// Set up a timer and events if enabled
if (Enabled)
@ -174,13 +179,24 @@ namespace Acacia.ZPush
#region Task execution
/// <summary>
/// Executes the tasks for all known ZPush accounts
/// Executes the tasks for all known ZPush accounts. Only executed if enough time has passed since the last check.
/// </summary>
private void ExecuteTasks()
private void PossiblyExecuteTasks()
{
// Don't contact the network if Outlook is offline
if (ThisAddIn.Instance.IsOffline)
return;
// Check for time
DateTime now = DateTime.Now;
if (LastSyncTime != null && now.Subtract(LastSyncTime) < PeriodThrottle)
{
// Back off
return;
}
LastSyncTime = now;
// Execute tasks for all accounts
foreach (ZPushAccount account in _watcher.Accounts.GetAccounts())
ExecuteTasks(account);
}
@ -191,6 +207,11 @@ namespace Acacia.ZPush
/// </summary>
private void ExecuteTasks(ZPushAccount account)
{
// Don't contact the network if Outlook is offline
if (ThisAddIn.Instance.IsOffline)
return;
// Execute the tasks for the account
foreach (SyncTask task in _tasks)
{
Tasks.Task(task.GetInstance(account));
@ -202,7 +223,7 @@ namespace Acacia.ZPush
/// </summary>
private void _timer_Tick(object sender, EventArgs e)
{
ExecuteTasks();
PossiblyExecuteTasks();
}
/// <summary>
@ -225,7 +246,7 @@ namespace Acacia.ZPush
if (_started)
{
// Explicit sync, run tasks
ExecuteTasks();
PossiblyExecuteTasks();
}
}