mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-25 06:16:37 +01:00
CA-210549: Make MultipleAction and ParallelAction cancellable
- Fixed the way we calculate PercentComplete for ParallelAction: use the sum of actions in actionsByConnection and actionsWithNoConnection instead of subActions.Count, to avoid waiting for the completion of actions that we never start, because we exclude actions with disconnected connections from actionsByConnections
This commit is contained in:
parent
56038e3eba
commit
f914f03c21
@ -148,7 +148,7 @@ namespace XenAdmin.Actions
|
||||
}
|
||||
}
|
||||
|
||||
private void RecalculatePercentComplete()
|
||||
protected virtual void RecalculatePercentComplete()
|
||||
{
|
||||
int total = 0;
|
||||
int n = subActions.Count;
|
||||
|
@ -54,12 +54,16 @@ namespace XenAdmin.Actions
|
||||
private ProduceConsumerQueue queueWithNoConnection;
|
||||
|
||||
private readonly int maxNumberOfParallelActions;
|
||||
private int actionsCount;
|
||||
|
||||
public ParallelAction(IXenConnection connection, string title, string startDescription, string endDescription, List<AsyncAction> subActions, bool suppressHistory, bool showSubActionsDetails, int maxNumberOfParallelActions = DEFAULT_MAX_NUMBER_OF_PARALLEL_ACTIONS)
|
||||
: base(connection, title, startDescription, endDescription, subActions, suppressHistory, showSubActionsDetails)
|
||||
{
|
||||
if (Connection != null)
|
||||
{
|
||||
actionsByConnection.Add(Connection, subActions);
|
||||
actionsCount = subActions.Count;
|
||||
}
|
||||
else
|
||||
GroupActionsByConnection();
|
||||
this.maxNumberOfParallelActions = maxNumberOfParallelActions;
|
||||
@ -88,6 +92,7 @@ namespace XenAdmin.Actions
|
||||
|
||||
private void GroupActionsByConnection()
|
||||
{
|
||||
actionsCount = 0;
|
||||
foreach (AsyncAction action in subActions)
|
||||
{
|
||||
if (action.Connection != null)
|
||||
@ -100,11 +105,13 @@ namespace XenAdmin.Actions
|
||||
}
|
||||
|
||||
actionsByConnection[action.Connection].Add(action);
|
||||
actionsCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
actionsWithNoConnection.Add(action);
|
||||
actionsCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -163,6 +170,19 @@ namespace XenAdmin.Actions
|
||||
});
|
||||
}
|
||||
|
||||
protected override void RecalculatePercentComplete()
|
||||
{
|
||||
int total = 0;
|
||||
foreach (IXenConnection connection in actionsByConnection.Keys)
|
||||
{
|
||||
foreach (var action in actionsByConnection[connection])
|
||||
total += action.PercentComplete;
|
||||
}
|
||||
foreach (var action in actionsWithNoConnection)
|
||||
total += action.PercentComplete;
|
||||
PercentComplete = (int)(total / actionsCount);
|
||||
}
|
||||
|
||||
private readonly object _lock = new object();
|
||||
private volatile int i = 0;
|
||||
|
||||
@ -172,7 +192,7 @@ namespace XenAdmin.Actions
|
||||
lock (_lock)
|
||||
{
|
||||
i++;
|
||||
if (i == subActions.Count)
|
||||
if (i == actionsCount)
|
||||
{
|
||||
Monitor.Pulse(_lock);
|
||||
PercentComplete = 100;
|
||||
|
Loading…
Reference in New Issue
Block a user