Stop data sync after account authorization revoke
This commit is contained in:
@@ -190,24 +190,42 @@ public sealed class RemoteControlClient : IDisposable
|
||||
cancellationToken, RemoteDataProtocol.MaxBatchBytes).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<RemoteSyncBatch>> FlushDataBatchesAsync(
|
||||
RemoteDataBatchQueue queue,
|
||||
ReportingConfig reportingConfig,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
FlushDataBatchesAsync(queue, reportingConfig, new HashSet<string>(StringComparer.Ordinal), cancellationToken);
|
||||
|
||||
public async Task<IReadOnlyList<RemoteSyncBatch>> FlushDataBatchesAsync(
|
||||
RemoteDataBatchQueue queue,
|
||||
ReportingConfig reportingConfig,
|
||||
ISet<string> blockedAccountIds,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
EnsureAuthenticated();
|
||||
var confirmed = new List<RemoteSyncBatch>();
|
||||
foreach (var batch in queue.Pending())
|
||||
{
|
||||
if (blockedAccountIds.Contains(batch.AccountId))
|
||||
continue;
|
||||
var filtered = RemoteDataBatchAuthorization.Filter(reportingConfig, batch, out _);
|
||||
if (filtered is null)
|
||||
{
|
||||
queue.Drop(batch.BatchId);
|
||||
continue;
|
||||
}
|
||||
var acknowledgement = await SubmitDataBatchAsync(reportingConfig, filtered, cancellationToken).ConfigureAwait(false);
|
||||
if (acknowledgement.Accepted && queue.MarkConfirmed(acknowledgement))
|
||||
confirmed.Add(filtered);
|
||||
try
|
||||
{
|
||||
var acknowledgement = await SubmitDataBatchAsync(reportingConfig, filtered, cancellationToken).ConfigureAwait(false);
|
||||
if (acknowledgement.Accepted && queue.MarkConfirmed(acknowledgement))
|
||||
confirmed.Add(filtered);
|
||||
}
|
||||
catch (RemoteClientException exception) when (exception.StatusCode == 403 && exception.Code == "AccountNotAuthorized")
|
||||
{
|
||||
// Authorization revocation is terminal for locally buffered content: do not retain or retry it.
|
||||
queue.DropAllForAccount(batch.AccountId);
|
||||
blockedAccountIds.Add(batch.AccountId);
|
||||
}
|
||||
}
|
||||
return confirmed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user