CrazyIter_Bin 4 years ago
parent
commit
f6f26e57c1

+ 14 - 1
TEAMModelFunction/MonitorServicesBus.cs

@@ -16,10 +16,14 @@ namespace TEAMModelFunction
     {
     {
         private readonly AzureCosmosFactory _azureCosmos;
         private readonly AzureCosmosFactory _azureCosmos;
         private readonly DingDing _dingDing;
         private readonly DingDing _dingDing;
-        public MonitorServicesBus(AzureCosmosFactory azureCosmos, DingDing dingDing)
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly AzureRedisFactory _azureRedis;
+        public MonitorServicesBus(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
         {
         {
             _azureCosmos = azureCosmos;
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
             _dingDing = dingDing;
+            _azureStorage = azureStorage;
+            _azureRedis = azureRedis;
         }
         }
         [FunctionName("Exam")]
         [FunctionName("Exam")]
         public async Task Exam([ServiceBusTrigger("active-task", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
         public async Task Exam([ServiceBusTrigger("active-task", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
@@ -140,5 +144,14 @@ namespace TEAMModelFunction
                 await _dingDing.SendBotMsg($"ServiceBus,VoteBus()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"ServiceBus,VoteBus()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
             }
             }
         }
         }
+        [FunctionName("Blob")]
+        public async Task Blob([ServiceBusTrigger("active-task", "blob", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
+            var jsonMsg = JsonDocument.Parse(msg);
+            jsonMsg.RootElement.TryGetProperty("code", out JsonElement name);
+            var client = _azureStorage.GetBlobContainerClient($"{name}");
+            var size = await client.GetBlobsSize();
+            await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name.GetString(), size);
+            await _dingDing.SendBotMsg($"ServiceBus,Blob() 容器:{name}更新大小:{size}", GroupNames.醍摩豆服務運維群組);
+        }
     }
     }
 }
 }

+ 1 - 0
TEAMModelFunction/Startup.cs

@@ -21,6 +21,7 @@ namespace TEAMModelFunction
             builder.Services.AddAzureServiceBus(Environment.GetEnvironmentVariable("Azure:ServiceBus:ConnectionString"));
             builder.Services.AddAzureServiceBus(Environment.GetEnvironmentVariable("Azure:ServiceBus:ConnectionString"));
             builder.Services.AddAzureStorage(Environment.GetEnvironmentVariable("Azure:Starage:ConnectionString"));
             builder.Services.AddAzureStorage(Environment.GetEnvironmentVariable("Azure:Starage:ConnectionString"));
             builder.Services.AddAzureCosmos(Environment.GetEnvironmentVariable("Azure:Cosmos:ConnectionString"));
             builder.Services.AddAzureCosmos(Environment.GetEnvironmentVariable("Azure:Cosmos:ConnectionString"));
+            builder.Services.AddAzureRedis(Environment.GetEnvironmentVariable("Azure:Redis:ConnectionString"));
         }
         }
     }
     }
 }
 }

+ 1 - 0
TEAMModelFunction/local.settings.json

@@ -5,6 +5,7 @@
     "Azure:Starage:ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelstorage;AccountKey=Yq7D4dE6cFuer2d2UZIccTA/i0c3sJ/6ITc8tNOyW+K5f+/lWw9GCos3Mxhj47PyWQgDL8YbVD63B9XcGtrMxQ==;EndpointSuffix=core.chinacloudapi.cn",
     "Azure:Starage:ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelstorage;AccountKey=Yq7D4dE6cFuer2d2UZIccTA/i0c3sJ/6ITc8tNOyW+K5f+/lWw9GCos3Mxhj47PyWQgDL8YbVD63B9XcGtrMxQ==;EndpointSuffix=core.chinacloudapi.cn",
     "Azure:ServiceBus:ConnectionString": "Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
     "Azure:ServiceBus:ConnectionString": "Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
     "Azure:Cosmos:ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;",
     "Azure:Cosmos:ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;",
+    "Azure:Redis:ConnectionString": "CoreRedisCN.redis.cache.chinacloudapi.cn:6380,password=LyJWP1ORJdv+poXWofAF97lhCEQPg1wXWqvtzXGXQuE=,ssl=True,abortConnect=False",
     "FUNCTIONS_WORKER_RUNTIME": "dotnet",
     "FUNCTIONS_WORKER_RUNTIME": "dotnet",
     "ScanModel": "TEAMModelOS",
     "ScanModel": "TEAMModelOS",
     "Database": "TEAMModelOS"
     "Database": "TEAMModelOS"

+ 21 - 11
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -17,6 +17,7 @@ using System.IdentityModel.Tokens.Jwt;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.Filter;
 using TEAMModelOS.Filter;
 using StackExchange.Redis;
 using StackExchange.Redis;
+using Azure.Messaging.ServiceBus;
 
 
 namespace TEAMModelOS.Controllers.Core
 namespace TEAMModelOS.Controllers.Core
 {
 {
@@ -236,17 +237,23 @@ namespace TEAMModelOS.Controllers.Core
         {
         {
             
             
             request.TryGetProperty("containerName", out JsonElement containerName);
             request.TryGetProperty("containerName", out JsonElement containerName);
+            request.TryGetProperty("cache", out JsonElement cache);
             var name =containerName.GetString();
             var name =containerName.GetString();
-            //RedisValue value = default;
-            //value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
-            //if (value != default && !value.IsNullOrEmpty)
-            //{
-            //    JsonElement record = value.ToString().ToObject<JsonElement>();
-            //    if (record.TryGetInt64(out long blobsize))
-            //    {
-            //        return Ok(new { size= blobsize });
-            //    }
-            //}
+            try {
+                if (cache.GetBoolean())
+                {
+                    RedisValue value = default;
+                    value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
+                    if (value != default && !value.IsNullOrEmpty)
+                    {
+                        JsonElement record = value.ToString().ToObject<JsonElement>();
+                        if (record.TryGetInt64(out long blobsize))
+                        {
+                            return Ok(new { size = blobsize });
+                        }
+                    }
+                }
+            } catch { }
             var client = _azureStorage.GetBlobContainerClient(name);
             var client = _azureStorage.GetBlobContainerClient(name);
             var size = await client.GetBlobsSize();
             var size = await client.GetBlobsSize();
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size);
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size);
@@ -284,7 +291,10 @@ namespace TEAMModelOS.Controllers.Core
             }
             }
             useSize = useSize + disSize;
             useSize = useSize + disSize;
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, useSize);
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, useSize);
-            return Ok(new { disSize, urlsSize , useSize , blobSize });
+            var messageBlob = new ServiceBusMessage(new {id=Guid.NewGuid().ToString(), progress = "update",code=name}.ToJsonString());
+            messageBlob.ApplicationProperties.Add("name", "Blob");
+            await _serviceBus.GetServiceBusClient().SendMessageAsync("active-task", messageBlob);
+            return Ok(new { size=useSize });
         }
         }
 
 
         private static (string, string) BlobUrlString(string sasUrl)
         private static (string, string) BlobUrlString(string sasUrl)

+ 1 - 1
TEAMModelOS/JsonFile/Core/LangConfigV3.json

@@ -38,7 +38,7 @@
           "judge": "是非題",
           "judge": "是非題",
           "complete": "填充題",
           "complete": "填充題",
           "subjective": "問答題",
           "subjective": "問答題",
-          "connector": "連題",
+          "connector": "連題",
           "correct": "改錯題"
           "correct": "改錯題"
         },
         },
         "Answer": "答案",
         "Answer": "答案",