public override async Task <ScavengeResp> StartScavenge(StartScavengeReq request, ServerCallContext context) { var scavengeResultSource = new TaskCompletionSource <(string, ScavengeResp.Types.ScavengeResult)>(); var user = context.GetHttpContext().User; _queue.Publish(new ClientMessage.ScavengeDatabase(new CallbackEnvelope(OnMessage), Guid.NewGuid(), user, request.Options.StartFromChunk, request.Options.ThreadCount)); var(scavengeId, scavengeResult) = await scavengeResultSource.Task.ConfigureAwait(false); return(new ScavengeResp { ScavengeId = scavengeId, ScavengeResult = scavengeResult }); void OnMessage(Message message) => HandleScavengeDatabaseResponse(message, scavengeResultSource); }
public override async Task <ScavengeResp> StartScavenge(StartScavengeReq request, ServerCallContext context) { var scavengeResultSource = new TaskCompletionSource <(string, ScavengeResp.Types.ScavengeResult)>(); var user = context.GetHttpContext().User; if (!await _authorizationProvider.CheckAccessAsync(user, StartOperation, context.CancellationToken).ConfigureAwait(false)) { throw AccessDenied(); } _publisher.Publish(new ClientMessage.ScavengeDatabase(new CallbackEnvelope(OnMessage), Guid.NewGuid(), user, request.Options.StartFromChunk, request.Options.ThreadCount)); var(scavengeId, scavengeResult) = await scavengeResultSource.Task.ConfigureAwait(false); return(new ScavengeResp { ScavengeId = scavengeId, ScavengeResult = scavengeResult }); void OnMessage(Message message) => HandleScavengeDatabaseResponse(message, scavengeResultSource); }