【发布时间】:2019-08-21 07:06:26
【问题描述】:
我编写了一个存储过程,用于根据文档的更新日期从 cosmosDB 中删除记录。 cosmosDB 集合具有大量(例如 500 个)分区键,因此我必须执行存储过程 500 次。 我正在尝试从 Azure 时间触发函数执行一个 azure 存储过程。
下面是用azure触发函数编写的代码:
添加了新文件 project.json
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.Azure.DocumentDB": "2.0.0"
}
}
}
}
run.csx 文件更新如下。
#r "Microsoft.Azure.Documents.Client"
using System;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
public static async Task Run(TimerInfo myTimer, IEnumerable<dynamic>
inputDocument, TraceWriter log)
{
log.Info($"C# Timer trigger function started at: {DateTime.Now}");
// Get the date 6 months before from Current Time in IST and convert to Epoch value.
TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India
Standard Time");
DateTime indianTime =
TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow.AddDays(-180),
INDIAN_ZONE);
long epochTime = (long)(indianTime - new DateTime(1970, 1,
1)).TotalSeconds;
DocumentClient client;
string endpoint = "https://***cosmosdb.documents.azure.com:443/";
string key = "****";
client = new DocumentClient(new Uri(endpoint), key);
foreach (var doc in inputDocument)
{
string partKey = doc.NUM;
StoredProcedureResponse<bool> sprocResponse = await
client.ExecuteStoredProcedureAsync<bool>(
"/dbs/DB_NAME/colls/COLLECTION_NAME/sprocs/STORED PROC_NAME/",new
RequestOptions { PartitionKey = new PartitionKey(partKey) });
log.Info($"Cosmos DB is updated at: {DateTime.Now}");
}
}
编译上述代码时出现以下错误。
2019-08-22T15:30:01.759 [Error] Exception while executing function: Functions.TimerTriggerCSharp1. Microsoft.Azure.WebJobs.Script: One or more errors occurred. Microsoft.Azure.Documents.Client: Failed to deserialize stored procedure response or convert it to type 'System.Boolean': Unexpected character encountered while parsing value: {. Path '', line 1, position 1. Newtonsoft.Json: Unexpected character encountered while parsing value: {. Path '', line 1, position 1.
2019-08-22T15:30:01.822 [Error] Function completed (Failure, Id=02da4d71-8207-4227-9c79-1cc277439c20, Duration=1814ms)
在执行存储过程时,我必须传递一个日期参数和分区键数组。 我完全被困在这个阶段。可以做些什么来解决这个问题?
【问题讨论】:
标签: azure azure-functions azure-cosmosdb azure-cosmosdb-sqlapi