public async Task <int> EvalPEmbeddedNotifications()
        {
            int nNotification            = 0;
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       = queueClient.GetQueueReference("embeddernotification");

            foreach (CloudQueueMessage message in await queue.GetMessagesAsync(20, TimeSpan.FromMinutes(60), null, null))
            {
                try
                {
                    NotificationEmbedder rawdata = Newtonsoft.Json.JsonConvert.DeserializeObject <NotificationEmbedder>(message.AsString);
                    WaterMarkedRender    data    = GetWaterMarkedRender(rawdata.AssetID, rawdata.EmbebedCode, rawdata.FileName);
                    string url = data.MP4URL;
                    data = new WaterMarkedRender(rawdata, url);
                    var outputData = UpdateWaterMarkedRender(data);
                }
                catch (Exception X)
                {
                    Trace.TraceError($"EvalPEmbeddedNotifications Error: {X.Message}");
                    CloudQueue deadletter = queueClient.GetQueueReference("deadletter");
                    await deadletter.AddMessageAsync(message);
                }
                await queue.DeleteMessageAsync(message);

                nNotification += 1;
            }
            return(nNotification);
        }
Beispiel #2
0
        public async Task <int> EvalPEmbeddedNotifications(string JobId)
        {
            int nNotification            = 0;
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       = queueClient.GetQueueReference("embeddernotification");

            //Process more than 32 message
            for (int i = 0; i < _embeddedmessagecount; i++)
            {
                bool swMetaLoop = true;
                foreach (CloudQueueMessage message in await queue.GetMessagesAsync(_embeddedmessagecount, TimeSpan.FromMinutes(10), null, null))
                {
                    swMetaLoop = false;
                    //Trace.TraceInformation($"[{JobId}] {message.AsString}");
                    try
                    {
                        NotificationEmbedder rawdata = Newtonsoft.Json.JsonConvert.DeserializeObject <NotificationEmbedder>(message.AsString);
                        rawdata.JobID = rawdata.JobID.Split('-')[0];
                        Trace.TraceInformation($"JobId={JobId} and messageJobId={rawdata.JobID}");
                        // This message if for JOB
                        WaterMarkedRender data = GetWaterMarkedRender(rawdata.AssetID, rawdata.EmbebedCode, rawdata.FileName);
                        string            url  = data.MP4URL;
                        //Adding Idempotent control for exceptional case of recieve multiple time
                        //notifications from K8S container (fail on container)
                        if (data.State == ExecutionStatus.Running)
                        {
                            //WatermarkRender is on right state(first message)
                            data = new WaterMarkedRender(rawdata, url);
                            var outputData = UpdateWaterMarkedRender(data);
                            Trace.TraceInformation($"{JobId} processesd Message {rawdata.Status} ");
                        }
                        else
                        {
                            //poison message, means Embbedecode was already porcessed
                            Trace.TraceInformation($"{rawdata.JobID} Idenpotent Message Control  {message.AsString}");
                            await SendToDeadLetterQueue(queueClient, message.AsString);
                        }
                    }
                    catch (Exception X)
                    {
                        Trace.TraceError($"[{JobId}] EvalPEmbeddedNotifications Error: {X.Message}");
                        await SendToDeadLetterQueue(queueClient, message.AsString);
                    }

                    await queue.DeleteMessageAsync(message);

                    nNotification += 1;
                }

                //No more Message
                if (swMetaLoop)
                {
                    Trace.TraceInformation($"[{JobId}] No more messages");
                    break;
                }
            }
            return(nNotification);
        }