瀏覽代碼

异常处理

zhouj1203@hotmail.com 4 年之前
父節點
當前提交
24d048cda2
共有 3 個文件被更改,包括 207 次插入180 次删除
  1. 125 123
      TEAMModelFunction/MonitorCosmosDB.cs
  2. 79 54
      TEAMModelFunction/ServiceBusTopic.cs
  3. 3 3
      TEAMModelFunction/local.settings.json

+ 125 - 123
TEAMModelFunction/MonitorCosmosDB.cs

@@ -16,13 +16,13 @@ namespace TEAMModelFunction
 {
     public class MonitorCosmosDB
     {
-        private readonly IHttpClientFactory _clientFactory;
         private readonly AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
 
-        public MonitorCosmosDB( IHttpClientFactory clientFactory,AzureCosmosFactory azureCosmos)
+        public MonitorCosmosDB( IHttpClientFactory clientFactory,AzureCosmosFactory azureCosmos,DingDing dingDing)
         {
-            _clientFactory = clientFactory;
             _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
     }
 
         [FunctionName("School")]
@@ -31,155 +31,157 @@ namespace TEAMModelFunction
             collectionName: "Common",
             ConnectionStringSetting = "CosmosConnection",
             LeaseCollectionName = "leases")]IReadOnlyList<Document> input, ILogger log)
-        {          
-                if (input != null && input.Count > 0)
-                {
-                    log.LogInformation("Documents modified " + input.Count);
-                    log.LogInformation("First document Id " + input[0].Id);
-                }
-            //input[0]
-            var client = _azureCosmos.GetCosmosClient();
-            List<ExamInfo> exams = new List<ExamInfo>();
-            string pk = input[0].GetPropertyValue<string>("pk");
-            if (!string.IsNullOrEmpty(pk) &&  pk.Equals("Exam",StringComparison.OrdinalIgnoreCase)) {
-                string code = input[0].GetPropertyValue<string>("code");
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.id = '{input[0].Id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{code}") }))
+        {
+            try {
+                var client = _azureCosmos.GetCosmosClient();
+                List<ExamInfo> exams = new List<ExamInfo>();
+                string pk = input[0].GetPropertyValue<string>("pk");
+                if (!string.IsNullOrEmpty(pk) && pk.Equals("Exam", StringComparison.OrdinalIgnoreCase))
                 {
-                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    string code = input[0].GetPropertyValue<string>("code");
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.id = '{input[0].Id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{code}") }))
                     {
-                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                         {
+                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                            {
 
-                            exams.Add(obj.ToObject<ExamInfo>());
+                                exams.Add(obj.ToObject<ExamInfo>());
+                            }
                         }
                     }
-                }
-                for (int i = 0; i < exams.Count; i++)
-                {
-                    List<ExamClassResult> examClassResults = new List<ExamClassResult>();
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{exams[i].id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{code}") }))
+                    for (int i = 0; i < exams.Count; i++)
                     {
-                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                        List<ExamClassResult> examClassResults = new List<ExamClassResult>();
+                        await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{exams[i].id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{code}") }))
                         {
-                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                            using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                            if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                             {
-                                examClassResults.Add(obj.ToObject<ExamClassResult>());
+                                foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                                {
+                                    examClassResults.Add(obj.ToObject<ExamClassResult>());
+                                }
                             }
                         }
-                    }
-                    /*if (exams[i].startTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) < 0 
-                        && exams[i].endTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) > 0 )
-                    {*/
-                    if (examClassResults.Count < 0 ) {
-                        if (exams[i].progress.Equals("going",StringComparison.OrdinalIgnoreCase))
+                        /*if (exams[i].startTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) < 0 
+                            && exams[i].endTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) > 0 )
+                        {*/
+                        if (examClassResults.Count < 0)
                         {
-
-                            //await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exams[i], exams[i].id.ToString(), new Azure.Cosmos.PartitionKey($"{exams[i].code}"));
-                            for (int j = 0; j < exams[i].subjects.Count; j++)
+                            if (exams[i].progress.Equals("going", StringComparison.OrdinalIgnoreCase))
                             {
-                                for (int k = 0; k < exams[i].targetClassIds.Count; k++)
+
+                                //await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exams[i], exams[i].id.ToString(), new Azure.Cosmos.PartitionKey($"{exams[i].code}"));
+                                for (int j = 0; j < exams[i].subjects.Count; j++)
                                 {
-                                    ExamClassResult result = new ExamClassResult();
-                                    result.code = "ExamClassResult-" + exams[i].school;
-                                    result.examId = exams[i].id;
-                                    result.id = Guid.NewGuid().ToString();
-                                    result.subjectId = exams[i].subjects[j].id;
-                                    result.year = exams[i].year;
-                                    result.ttl = -1;
-                                    result.scope = exams[i].scope;
-                                    result.pk = typeof(ExamClassResult).Name;
-                                    result.info.id = exams[i].targetClassIds[k];
-                                    var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(exams[i].targetClassIds[k], new Azure.Cosmos.PartitionKey($"Class-{exams[i].school}"));
-                                    if (sresponse.Status == 200)
+                                    for (int k = 0; k < exams[i].targetClassIds.Count; k++)
                                     {
-                                        using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
-                                        Classroom classroom = json.ToObject<Classroom>();
-                                        result.info.name = classroom.name;
-                                        List<List<string>> ans = new List<List<string>>();
-                                        List<double> ansPoint = new List<double>();
-                                        foreach (double p in exams[i].papers[j].point)
-                                        {
-                                            ans.Add(new List<string>());
-                                            ansPoint.Add(0);
-                                        }
-                                        foreach (StudentSimple stu in classroom.students)
+                                        ExamClassResult result = new ExamClassResult();
+                                        result.code = "ExamClassResult-" + exams[i].school;
+                                        result.examId = exams[i].id;
+                                        result.id = Guid.NewGuid().ToString();
+                                        result.subjectId = exams[i].subjects[j].id;
+                                        result.year = exams[i].year;
+                                        result.ttl = -1;
+                                        result.scope = exams[i].scope;
+                                        result.pk = typeof(ExamClassResult).Name;
+                                        result.info.id = exams[i].targetClassIds[k];
+                                        var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(exams[i].targetClassIds[k], new Azure.Cosmos.PartitionKey($"Class-{exams[i].school}"));
+                                        if (sresponse.Status == 200)
                                         {
-                                            result.studentIds.Add(stu.id);
-                                            result.studentAnswers.Add(ans);
-                                            result.studentScores.Add(ansPoint);
+                                            using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
+                                            Classroom classroom = json.ToObject<Classroom>();
+                                            result.info.name = classroom.name;
+                                            List<List<string>> ans = new List<List<string>>();
+                                            List<double> ansPoint = new List<double>();
+                                            foreach (double p in exams[i].papers[j].point)
+                                            {
+                                                ans.Add(new List<string>());
+                                                ansPoint.Add(0);
+                                            }
+                                            foreach (StudentSimple stu in classroom.students)
+                                            {
+                                                result.studentIds.Add(stu.id);
+                                                result.studentAnswers.Add(ans);
+                                                result.studentScores.Add(ansPoint);
+                                            }
                                         }
-                                    }
-                                    result.progress = exams[i].progress;
-                                    result.school = exams[i].school;
-                                    await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
+                                        result.progress = exams[i].progress;
+                                        result.school = exams[i].school;
+                                        await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
 
+                                    }
                                 }
                             }
                         }
-                    }
-                    if (exams[i].progress.Equals("finish",StringComparison.OrdinalIgnoreCase))
-                    {
-                        for (int j = 0; j < exams[i].subjects.Count; j++)
+                        if (exams[i].progress.Equals("finish", StringComparison.OrdinalIgnoreCase))
                         {
-                            ExamResult result = new ExamResult();
-                            result.ttl = -1;
-                            result.pk = typeof(ExamResult).Name;
-                            result.code = "ExamResult-" + exams[i].school;
-                            result.school = exams[i].school;
-                            result.id = Guid.NewGuid().ToString();
-                            result.examId = exams[i].id;
-                            result.subjectId = exams[i].subjects[j].id;
-                            result.year = exams[i].year;
-                            result.paper = exams[i].papers[j];
-                            result.point = exams[i].papers[j].point;
-                            result.scope = exams[i].scope;
-                            result.name = exams[i].name;
-                            //result.time
-
-                            //人数总和
-                            int Count = 0;
-                            int m = 0;
-                            List<ClassRange> classRanges = new List<ClassRange>();
-                            foreach (ExamClassResult classResult in examClassResults)
+                            for (int j = 0; j < exams[i].subjects.Count; j++)
                             {
-                                //处理班级信息
-                                ClassRange range = new ClassRange();
-                                range.id = classResult.info.id;
-                                range.name = classResult.info.name;
-                                List<int> ran = new List<int>();
-                                int stuCount = classResult.studentIds.Count;
-                                Count += stuCount;
-                                if (m == 0)
-                                {
-                                    ran.Add(0);
-                                    ran.Add(stuCount - 1);
-                                }
-                                else
-                                {
-                                    ran.Add(Count - stuCount);
-                                    ran.Add(Count - 1);
-                                }
-                                m++;
-                                range.range = ran;
-                                classRanges.Add(range);
-                                //处理学生ID
-                                foreach (string id in classResult.studentIds)
-                                {
-                                    result.studentIds.Add(id);
-                                }
-                                foreach (List<double> scores in classResult.studentScores)
+                                ExamResult result = new ExamResult();
+                                result.ttl = -1;
+                                result.pk = typeof(ExamResult).Name;
+                                result.code = "ExamResult-" + exams[i].school;
+                                result.school = exams[i].school;
+                                result.id = Guid.NewGuid().ToString();
+                                result.examId = exams[i].id;
+                                result.subjectId = exams[i].subjects[j].id;
+                                result.year = exams[i].year;
+                                result.paper = exams[i].papers[j];
+                                result.point = exams[i].papers[j].point;
+                                result.scope = exams[i].scope;
+                                result.name = exams[i].name;
+                                //result.time
+
+                                //人数总和
+                                int Count = 0;
+                                int m = 0;
+                                List<ClassRange> classRanges = new List<ClassRange>();
+                                foreach (ExamClassResult classResult in examClassResults)
                                 {
-                                    result.studentScores.Add(scores);
+                                    //处理班级信息
+                                    ClassRange range = new ClassRange();
+                                    range.id = classResult.info.id;
+                                    range.name = classResult.info.name;
+                                    List<int> ran = new List<int>();
+                                    int stuCount = classResult.studentIds.Count;
+                                    Count += stuCount;
+                                    if (m == 0)
+                                    {
+                                        ran.Add(0);
+                                        ran.Add(stuCount - 1);
+                                    }
+                                    else
+                                    {
+                                        ran.Add(Count - stuCount);
+                                        ran.Add(Count - 1);
+                                    }
+                                    m++;
+                                    range.range = ran;
+                                    classRanges.Add(range);
+                                    //处理学生ID
+                                    foreach (string id in classResult.studentIds)
+                                    {
+                                        result.studentIds.Add(id);
+                                    }
+                                    foreach (List<double> scores in classResult.studentScores)
+                                    {
+                                        result.studentScores.Add(scores);
+                                    }
                                 }
+                                result.classes = classRanges;
+                                await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{result.school}"));
                             }
-                            result.classes = classRanges;
-                            await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{result.school}"));
                         }
                     }
                 }
-            }           
+            } catch (Exception e) {
+                await _dingDing.SendBotMsg($"CosmosDB_common,School()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                return;
+            }
+                     
         }
     }
 }

+ 79 - 54
TEAMModelFunction/ServiceBusTopic.cs

@@ -11,81 +11,106 @@ using TEAMModelOS.SDK.Extension;
 
 namespace TEAMModelFunction
 {
-    public   class ServiceBusTopic
+    public  class ServiceBusTopic
     {
         private readonly AzureCosmosFactory _azureCosmos;
-        public ServiceBusTopic(  AzureCosmosFactory azureCosmos)
+        private readonly DingDing _dingDing;
+        public ServiceBusTopic(  AzureCosmosFactory azureCosmos, DingDing dingDing)
         {
             _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
         }
         [FunctionName("ServiceBusTopic")]
         public async Task ExamBus([ServiceBusTrigger("active-task", "active-exam-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
         {
-            Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
-            var client = _azureCosmos.GetCosmosClient();
-            keyValuePairs.TryGetValue("id", out object id);
-            keyValuePairs.TryGetValue("name", out object name);
-            keyValuePairs.TryGetValue("code", out object code);
-            //keyValuePairs.TryGetValue("status", out object progress);
-            if (name.ToString().Equals("ExamInfo",StringComparison.OrdinalIgnoreCase)) {
-                ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
-                if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) < 0) {
-                    exam.progress = "going";
-                } else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) > 0) {
-                    exam.progress = "finish";
-                }               
-                await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
-            }                 
-        }
-        public async Task VoteBus([ServiceBusTrigger("active-task", "active-vote-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
-        {
-            Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
-            var client = _azureCosmos.GetCosmosClient();
-            keyValuePairs.TryGetValue("id", out object id);
-            keyValuePairs.TryGetValue("name", out object name);
-            keyValuePairs.TryGetValue("code", out object code);
-            //keyValuePairs.TryGetValue("status", out object progress);
-            if (name.ToString().Equals("Vote",StringComparison.OrdinalIgnoreCase)) {
-                Vote vote;
-                var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
-                if (sresponse.Status == 200)
+            try
+            {
+                Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
+                var client = _azureCosmos.GetCosmosClient();
+                keyValuePairs.TryGetValue("id", out object id);
+                keyValuePairs.TryGetValue("name", out object name);
+                keyValuePairs.TryGetValue("code", out object code);
+                //keyValuePairs.TryGetValue("status", out object progress);
+                if (name.ToString().Equals("ExamInfo", StringComparison.OrdinalIgnoreCase))
                 {
-                    using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
-                    vote = json.ToObject<Vote>();
-                    if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) < 0)
+                    ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
+                    if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) < 0)
                     {
-                        vote.progress = "going";
+                        exam.progress = "going";
                     }
-                    else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) > 0)
+                    else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) > 0)
                     {
-                        vote.progress = "finish";
+                        exam.progress = "finish";
                     }
-                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
+                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
                 }
-            }                
+            } catch (Exception ex) {
+                await _dingDing.SendBotMsg($"ServiceBus,ExamBus()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return;
+            }
+                              
         }
-        public async Task SurveyBus([ServiceBusTrigger("active-task", "active-survey-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
+        public async Task VoteBus([ServiceBusTrigger("active-task", "active-vote-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
         {
-            Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
-            var client = _azureCosmos.GetCosmosClient();
-            keyValuePairs.TryGetValue("id", out object id);
-            keyValuePairs.TryGetValue("name", out object name);
-            keyValuePairs.TryGetValue("code", out object code);
-            //keyValuePairs.TryGetValue("status", out object progress);
-            if (name.ToString().Equals("Survey",StringComparison.OrdinalIgnoreCase))
-            {
-                Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
-                if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) < 0)
+            try {
+                Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
+                var client = _azureCosmos.GetCosmosClient();
+                keyValuePairs.TryGetValue("id", out object id);
+                keyValuePairs.TryGetValue("name", out object name);
+                keyValuePairs.TryGetValue("code", out object code);
+                //keyValuePairs.TryGetValue("status", out object progress);
+                if (name.ToString().Equals("Vote", StringComparison.OrdinalIgnoreCase))
                 {
-                    survey.progress = "going";
+                    Vote vote;
+                    var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
+                    if (sresponse.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
+                        vote = json.ToObject<Vote>();
+                        if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) < 0)
+                        {
+                            vote.progress = "going";
+                        }
+                        else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) > 0)
+                        {
+                            vote.progress = "finish";
+                        }
+                        await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
+                    }
                 }
-                else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) > 0)
+            } catch (Exception ex){
+                await _dingDing.SendBotMsg($"ServiceBus,VoteBus()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return;
+            }
+                         
+        }
+        public async Task SurveyBus([ServiceBusTrigger("active-task", "active-survey-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
+        {
+            try {
+                Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
+                var client = _azureCosmos.GetCosmosClient();
+                keyValuePairs.TryGetValue("id", out object id);
+                keyValuePairs.TryGetValue("name", out object name);
+                keyValuePairs.TryGetValue("code", out object code);
+                //keyValuePairs.TryGetValue("status", out object progress);
+                if (name.ToString().Equals("Survey", StringComparison.OrdinalIgnoreCase))
                 {
-                    survey.progress = "finish";
+                    Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
+                    if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) < 0)
+                    {
+                        survey.progress = "going";
+                    }
+                    else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) > 0)
+                    {
+                        survey.progress = "finish";
+                    }
+                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
                 }
-                await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
             }
-            
+            catch (Exception ex){
+                await _dingDing.SendBotMsg($"ServiceBus,VoteBus()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return;
+            }                       
         }
     }
 }

+ 3 - 3
TEAMModelFunction/local.settings.json

@@ -3,9 +3,9 @@
   "Values": {
     "AzureWebJobsStorage": "UseDevelopmentStorage=true",
     "FUNCTIONS_WORKER_RUNTIME": "dotnet",
-    "ConnectionBusName": "Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
+    "ConnectionBusName": "Endpoint=sb://coreiotservicebuscnpro.servicebus.chinacloudapi.cn/;SharedAccessKeyName=TEAMModelOS;SharedAccessKey=llRPBMDJG9w1Nnifj+pGhV0g4H2REcq0PjvX2qqpcOg=",
     "CosmosConnection": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;",
-    "ScanModel": "TEAMModelOS" ,
-    "Database":  "TEAMModelOS" 
+    "ScanModel": "TEAMModelOS",
+    "Database": "TEAMModelOS"
   }  
 }