neo4j 任务已被取消
neo4j a Task has been canceled
我将以下代码用于一般性地 link neo 4j 中的顶点
public async Task LinkVertices<TSource, TTarget>(Expression<Func<TSource, TTarget, bool>> join, string relationName)
{
string sourceName = typeof(TSource).Name;
string targetName = typeof(TTarget).Name;
var span = (int)TimeSpan.FromMinutes(20).TotalMilliseconds;
try
{
await client.Cypher
.Match(string.Format("({0}:{0})", sourceName), string.Format("({0}:{0})", targetName))
.Where(join)
.Create(string.Format("{0}-[:{2}]->{1}", sourceName, targetName, relationName))
.MaxExecutionTime(span)
.ExecuteWithoutResultsAsync();
}
当我 link 处理速度比工作速度更快的数据较少时
我将 MaxExecutionTime 设置为 20 分钟,但总是在 100 秒后得到 TaskCanceledException
。
当我使用非异步执行方法时也会发生这种情况。
"Normal" 堆栈跟踪:
at Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteCypher(CypherQuery query) in D:\temp\f6198f8\Neo4jClient\GraphClient.cs:line 1072
at Neo4jClient.Cypher.CypherFluentQuery.ExecuteWithoutResults() in D:\temp\f6198f8\Neo4jClient\Cypher\CypherFluentQuery.cs:line 392
at Graph.Neo4JGateway.<LinkVertices>d__3`2.MoveNext() in
AsyncStack 跟踪:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at Neo4jClient.GraphClient.<>c__86`1.<PrepareCypherRequest>b__86_1(Task`1 response) in D:\temp\f6198f8\Neo4jClient\GraphClient.cs:line 979
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Neo4jClient.GraphClient.<Neo4jClient-IRawGraphClient-ExecuteCypherAsync>d__90.MoveNext() in D:\temp\f6198f8\Neo4jClient\GraphClient.cs:line 1088
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Graph.Neo4JGateway.<LinkVertices>d__3`2.MoveNext()
我还缺少另一个超时吗?
听起来可能是 HttpClient
超时。默认值为 100 秒。
如果您使用的是 user/pass,那么这将不起作用 - 我们将不得不走稍微复杂的路线,但如果您可以在没有 user/pass 的情况下进行测试,那我可以补充一下。
var client = new GraphClient(new Uri("http://localhost.:7474/db/data"),
new HttpClientWrapper(
new HttpClient() { Timeout = TimeSpan.FromMinutes(20)})
);
我们在此处传递自定义 HttpClientWrapper
实例,Timeout
设置为 20 分钟。
编辑
刚刚检查过,我在 LinqPad 中使用的是旧版本,已更新,您可以使用 user/pass:
var gc = new GraphClient(new Uri("http://localhost.:7474/db/data"),
new HttpClientWrapper("user", "pass",
new HttpClient() { Timeout = TimeSpan.FromMinutes(20)})
);
我将以下代码用于一般性地 link neo 4j 中的顶点
public async Task LinkVertices<TSource, TTarget>(Expression<Func<TSource, TTarget, bool>> join, string relationName)
{
string sourceName = typeof(TSource).Name;
string targetName = typeof(TTarget).Name;
var span = (int)TimeSpan.FromMinutes(20).TotalMilliseconds;
try
{
await client.Cypher
.Match(string.Format("({0}:{0})", sourceName), string.Format("({0}:{0})", targetName))
.Where(join)
.Create(string.Format("{0}-[:{2}]->{1}", sourceName, targetName, relationName))
.MaxExecutionTime(span)
.ExecuteWithoutResultsAsync();
}
当我 link 处理速度比工作速度更快的数据较少时
我将 MaxExecutionTime 设置为 20 分钟,但总是在 100 秒后得到 TaskCanceledException
。
当我使用非异步执行方法时也会发生这种情况。
"Normal" 堆栈跟踪:
at Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteCypher(CypherQuery query) in D:\temp\f6198f8\Neo4jClient\GraphClient.cs:line 1072
at Neo4jClient.Cypher.CypherFluentQuery.ExecuteWithoutResults() in D:\temp\f6198f8\Neo4jClient\Cypher\CypherFluentQuery.cs:line 392
at Graph.Neo4JGateway.<LinkVertices>d__3`2.MoveNext() in
AsyncStack 跟踪:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at Neo4jClient.GraphClient.<>c__86`1.<PrepareCypherRequest>b__86_1(Task`1 response) in D:\temp\f6198f8\Neo4jClient\GraphClient.cs:line 979
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Neo4jClient.GraphClient.<Neo4jClient-IRawGraphClient-ExecuteCypherAsync>d__90.MoveNext() in D:\temp\f6198f8\Neo4jClient\GraphClient.cs:line 1088
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Graph.Neo4JGateway.<LinkVertices>d__3`2.MoveNext()
我还缺少另一个超时吗?
听起来可能是 HttpClient
超时。默认值为 100 秒。
如果您使用的是 user/pass,那么这将不起作用 - 我们将不得不走稍微复杂的路线,但如果您可以在没有 user/pass 的情况下进行测试,那我可以补充一下。
var client = new GraphClient(new Uri("http://localhost.:7474/db/data"),
new HttpClientWrapper(
new HttpClient() { Timeout = TimeSpan.FromMinutes(20)})
);
我们在此处传递自定义 HttpClientWrapper
实例,Timeout
设置为 20 分钟。
编辑
刚刚检查过,我在 LinqPad 中使用的是旧版本,已更新,您可以使用 user/pass:
var gc = new GraphClient(new Uri("http://localhost.:7474/db/data"),
new HttpClientWrapper("user", "pass",
new HttpClient() { Timeout = TimeSpan.FromMinutes(20)})
);