CosmosDB存储过程400

时间:2018-04-09 19:54:40

标签: azure-cosmosdb

我正在编写一个过期的存储过程,该过程的工作日期是将文档输入cosmosDB的日期。我也在使用SQL Api。我能够执行存储过程并使用延续模型调用它,但随机存储过程失败,我不知道为什么。

这是我用

得到的错误
System.AggregateException: One or more errors occurred. 
---> Microsoft.Azure.Documents.DocumentClientException: Message: 
{"Errors":["Encountered exception while executing function. Exception = Error   
 Stack trace:    
 at Anonymous function (purgeStaleActivity.js:40:24)
 at Anonymous function (purgeStaleActivity.js:839:29)"]}  

 ActivityId: 5f32323e-619f-4a50-b073-5edbd41c6357, Request URI: /apps/6628b461-75d4-4e4a-9897-ada4076dc30c/services/883314f1-064a-4921-9202-b5d8ca905550/partitions/832a92d6-a846-4e32-b18d-194f7c14ff85/replicas/131674305234651764p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.21.0.0, Windows/10.0.16299 documentdb-netcore-sdk/1.9.1  
 at Microsoft.Azure.Documents.Client.ClientExtensions.d__1.MoveNext()  
 --- End of stack trace from previous location where exception was thrown ---  
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
 at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  
 at Microsoft.Azure.Documents.GatewayStoreModel.c__DisplayClass20_0.b__0>d.MoveNext()  
 --- End of stack trace from previous location where exception was thrown ---    
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
 at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  
 at Microsoft.Azure.Documents.BackoffRetryUtility`1.c__DisplayClass1_0.b__0>d.MoveNext()  
 --- End of stack trace from previous location where exception was thrown ---  
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
 at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  
 at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__3.MoveNext()  
 --- End of stack trace from previous location where exception was thrown ---  
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 at Microsoft.Azure.Documents.BackoffRetryUtility`1.  d__3.MoveNext()  
 --- End of stack trace from previous location where exception was thrown ---  
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
 at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  
 at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__1.MoveNext()  
 --- End of stack trace from previous location where exception was thrown ---  
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
 at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  
 at Microsoft.Azure.Documents.GatewayStoreModel.d__20.MoveNext()  
 --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.GatewayStoreModel.d__12.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.Client.DocumentClient.d__256.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.Client.DocumentClient.d__219`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.c__DisplayClass1_0.b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__1.MoveNext()
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at System.Threading.Tasks.Task.Wait()
       at UserQuery.Main() in C:\Users\A750501\AppData\Local\Temp\LINQPad5\_bingnjxc\query_vbrkkj.cs:line 51
    ---> (Inner Exception #0) Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Encountered exception while executing function. Exception = Error\r\nStack trace: Error\n   at Anonymous function (purgeStaleActivity.js:40:24)\n   at Anonymous function (purgeStaleActivity.js:839:29)"]}
    ActivityId: 5f32323e-619f-4a50-b073-5edbd41c6357, Request URI: /apps/6628b461-75d4-4e4a-9897-ada4076dc30c/services/883314f1-064a-4921-9202-b5d8ca905550/partitions/832a92d6-a846-4e32-b18d-194f7c14ff85/replicas/131674305234651764p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.21.0.0, Windows/10.0.16299 documentdb-netcore-sdk/1.9.1
       at Microsoft.Azure.Documents.Client.ClientExtensions.d__1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.GatewayStoreModel.c__DisplayClass20_0.b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.c__DisplayClass1_0.b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.GatewayStoreModel.d__20.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.GatewayStoreModel.d__12.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.Client.DocumentClient.d__256.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.Client.DocumentClient.d__219`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.c__DisplayClass1_0.b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Azure.Documents.BackoffRetryUtility`1.d__1.MoveNext()

这是我要删除的存储过程:

// SAMPLE STORED PROCEDURE
function sample(expireTime) {
    var response = getContext().getResponse();
    var responseBody = {
        deleted:0,
        continuation: true
    };

    if(!expireTime) throw new Error("The expireTime must not be null");

    tryAndDelete();

    function tryAndDelete(continuation){
        var requestOptions = {continuation: continuation};

        var isAccepted =  __.filter(function(doc) {return doc.creationDate <= expireTime}, function(err, feed, responseOptions){
        if(err) throw err;

        if(feed.length > 0) {
            tryDelete(feed);
        }
        else if(responseOptions.continuation){
            tryAndDelete(responseOptions.continuation);
        }
        else {
            responseBody.continuation = false;
            response.setBody(responseBody);
        }
        });

        if(!isAccepted) {
            getContext().getResponse().SetBody(responseBody);
        }
    }

   function tryDelete(documents){
       if(documents.length > 0 ) {
           var isAccepted = __.deleteDocument(documents[0]._self, {} , function(err,responseOptions){
               console.log(err);
               if(err) throw err;

                responseBody.deleted++;
                documents.shift();
                tryDelete(documents);

           });

           if(isAccepted){
               response.setBody(responseBody);
           }
       }
       else {
             tryAndDelete();
       }
   }
}

我试图在数据探索中运行它来尝试获取console.log并使用requestoptions来启用脚本日志记录但是在我有机会读取门户上的控制台日志或检查之前抛出异常响应对象日志。

0 个答案:

没有答案