Revert async dispatcher change 08c74be (#1655)

* Revert 08c74be51f async message handling

* Fix merge error in SetEventHandler
This commit is contained in:
Karl Burtram
2022-08-29 10:44:26 -07:00
committed by GitHub
parent 6566a716b6
commit 3885c8f680
2 changed files with 48 additions and 58 deletions

View File

@@ -124,41 +124,36 @@ namespace Microsoft.SqlTools.Hosting.Protocol
requestType.MethodName, requestType.MethodName,
(requestMessage, messageWriter) => (requestMessage, messageWriter) =>
{ {
return Task.Run(async () => var requestContext =
{ new RequestContext<TResult>(
var requestContext = requestMessage,
new RequestContext<TResult>( messageWriter);
requestMessage, try
messageWriter); {
TParams typedParams = default(TParams);
try if (requestMessage.Contents != null)
{ {
TParams typedParams = default(TParams); try
if (requestMessage.Contents != null)
{ {
try typedParams = requestMessage.Contents.ToObject<TParams>();
{
typedParams = requestMessage.Contents.ToObject<TParams>();
}
catch (Exception ex)
{
throw new Exception($"{requestType.MethodName} : Error parsing message contents {requestMessage.Contents}", ex);
}
} }
catch (Exception ex)
{
throw new Exception($"{requestType.MethodName} : Error parsing message contents {requestMessage.Contents}", ex);
}
}
await requestHandler(typedParams, requestContext); return requestHandler(typedParams, requestContext);
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Error(ex); Logger.Error(ex);
await requestContext.SendError(ex); return requestContext.SendError(ex.Message);
} }
});
}); });
} }
public void SetEventHandler<TParams>( public void SetEventHandler<TParams>(
EventType<TParams> eventType, EventType<TParams> eventType,
Func<TParams, EventContext, Task> eventHandler) Func<TParams, EventContext, Task> eventHandler)
{ {
@@ -183,32 +178,29 @@ namespace Microsoft.SqlTools.Hosting.Protocol
eventType.MethodName, eventType.MethodName,
(eventMessage, messageWriter) => (eventMessage, messageWriter) =>
{ {
return Task.Run(async () => var eventContext = new EventContext(messageWriter);
{ TParams typedParams = default(TParams);
var eventContext = new EventContext(messageWriter); try
{
try if (eventMessage.Contents != null)
{ {
TParams typedParams = default(TParams); try
if (eventMessage.Contents != null)
{ {
try typedParams = eventMessage.Contents.ToObject<TParams>();
{
typedParams = eventMessage.Contents.ToObject<TParams>();
}
catch (Exception ex)
{
throw new Exception($"{eventType.MethodName} : Error parsing message contents {eventMessage.Contents}", ex);
}
} }
await eventHandler(typedParams, eventContext); catch (Exception ex)
} {
catch (Exception ex) Logger.Write(TraceEventType.Verbose, ex.ToString());
{ }
// There's nothing on the client side to send an error back to so just log the error and move on }
Logger.Error(ex); }
} catch (Exception ex)
}); {
// There's nothing on the client side to send an error back to so just log the error and move on
Logger.Error(ex);
}
return eventHandler(typedParams, eventContext);
}); });
} }
@@ -339,23 +331,21 @@ namespace Microsoft.SqlTools.Hosting.Protocol
// thread is not blocked. // thread is not blocked.
_ = Task.Run(() => _ = Task.Run(() =>
{ {
_ = RunTask(messageToDispatch, handlerToAwait); _ = RunTask(handlerToAwait);
}); });
} }
else else
{ {
await RunTask(messageToDispatch, handlerToAwait); await RunTask(handlerToAwait);
} }
} }
} }
private async Task RunTask(Message message, Task task) private async Task RunTask(Task task)
{ {
try try
{ {
Logger.Write(TraceEventType.Verbose, $"Processing message with id[{message.Id}], of type[{message.MessageType}] and method[{message.Method}]");
await task; await task;
Logger.Write(TraceEventType.Verbose, $"Finished processing message with id[{message.Id}], of type[{message.MessageType}] and method[{message.Method}]");
} }
catch (TaskCanceledException) catch (TaskCanceledException)
{ {

View File

@@ -1197,7 +1197,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
parameters.OwnerUri, parameters.OwnerUri,
out connInfo); out connInfo);
result.Success = true; result.Success = true;
result.Notebooks = await AgentNotebookHelper.GetAgentNotebooks(connInfo); result.Notebooks = AgentNotebookHelper.GetAgentNotebooks(connInfo).Result;
} }
catch (Exception e) catch (Exception e)
{ {
@@ -1246,7 +1246,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
ConnectionServiceInstance.TryFindConnection( ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri, parameters.OwnerUri,
out connInfo); out connInfo);
result.NotebookMaterialized = await AgentNotebookHelper.GetMaterializedNotebook(connInfo, parameters.NotebookMaterializedId, parameters.TargetDatabase); result.NotebookMaterialized = AgentNotebookHelper.GetMaterializedNotebook(connInfo, parameters.NotebookMaterializedId, parameters.TargetDatabase).Result;
result.Success = true; result.Success = true;
} }
catch (Exception e) catch (Exception e)