示例#1
0
        /// <summary>
        /// Send back to watcher a "Posion messsage" and delete from in queue
        /// </summary>
        /// <param name="poisonMessage">the poison message</param>
        /// <returns>Sueccess or not</returns>
        private bool SendPoisonMessage(CloudQueueMessage poisonMessage)
        {
            bool sw = false;

            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(myConfigData.ProcessConfigConn);
                CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
                CloudQueue          poisonQueue    = queueClient.GetQueueReference(myConfigData.poisonQueue);
                poisonQueue.CreateIfNotExists();

                MediaButler.Common.ButlerRequest  myButlerRequest  = Newtonsoft.Json.JsonConvert.DeserializeObject <ButlerRequest>(poisonMessage.AsString);
                MediaButler.Common.ButlerResponse myButlerResponse = new Common.ButlerResponse();

                myButlerResponse.MezzanineFiles = myButlerRequest.MezzanineFiles;
                ////Add to Mezzamine Files the control File URL if it exist
                //Becouse it is needed to move/delete the control file from processing to succes or fail
                if (!string.IsNullOrEmpty(myButlerRequest.ControlFileUri))
                {
                    myButlerResponse.MezzanineFiles.Add(myButlerRequest.ControlFileUri);
                }
                myButlerResponse.TimeStampProcessingCompleted = DateTime.Now.ToString();
                myButlerResponse.TimeStampProcessingStarted   = DateTime.Now.ToString();
                myButlerResponse.WorkflowName = myButlerRequest.WorkflowName;
                myButlerResponse.MessageId    = myButlerRequest.MessageId;
                myButlerResponse.TimeStampRequestSubmitted = myButlerRequest.TimeStampUTC;
                myButlerResponse.StorageConnectionString   = myButlerRequest.StorageConnectionString;
                myButlerResponse.Log = "Poison Message";

                //Lookin for Errors in Table Status
                CloudTableClient tableClient       = storageAccount.CreateCloudTableClient();
                CloudTable       table             = tableClient.GetTableReference(MediaButler.Common.Configuration.ButlerWorkflowStatus);
                TableOperation   retrieveOperation =
                    TableOperation.Retrieve <MediaButler.Common.workflow.ProcessSnapShot>(myButlerRequest.WorkflowName, myButlerRequest.MessageId.ToString());
                TableResult retrievedResult = table.Execute(retrieveOperation);
                if (retrievedResult.Result != null)
                {
                    //we have process info
                    var status = (MediaButler.Common.workflow.ProcessSnapShot)retrievedResult.Result;
                    try
                    {
                        var request = Newtonsoft.Json.JsonConvert.DeserializeObject <MediaButler.Common.workflow.ChainRequest>(status.jsonContext);
                        foreach (var error in request.Exceptions)
                        {
                            //myButlerResponse.Log += "\r\n" + error.Message;
                            myButlerResponse.Log += "\r\n" + error;
                        }
                    }
                    catch (Exception X)
                    {
                        Trace.TraceWarning("Unable to load Error LOG in response.log on poison message");
                        myButlerResponse.Log += "\r\n" + X.Message;
                        myButlerResponse.Log += "\r\n" + status.jsonContext;
                    }


                    //Delete register from Status table
                    TableOperation insertOperation = TableOperation.Delete(status);
                    table.Execute(insertOperation);
                }
                //Send Poison Mesagge
                CloudQueueMessage poison = new CloudQueueMessage(Newtonsoft.Json.JsonConvert.SerializeObject(myButlerResponse));
                poisonQueue.AddMessage(poison);
                sw = true;
            }
            catch (Exception X)
            {
                string txt = string.Format("[{0}] at {1} has an error: {2}", this.GetType().FullName, "GetNewMessage", X.Message);
                Trace.TraceError(txt);
            }
            return(sw);
        }
示例#2
0
        /// <summary>
        /// Submit this job to the Butler Request queue
        /// </summary>
        /// <param name="j">Job to submit</param>
        /// <returns>the Guid of the JOB if submission was successful</returns>
        public static Guid Submit(ButlerJob j, string storageAccountString)
        {
            CloudStorageAccount account = CloudStorageAccount.Parse(storageAccountString);
            CloudQueueClient sendQueueClient = account.CreateCloudQueueClient();
            try
            {
                CloudQueue sendQueue = sendQueueClient.GetQueueReference(Configuration.ButlerSendQueue);
                sendQueue.CreateIfNotExists();

                var message = new ButlerRequest
                {
                    MessageId = j.JobId,
                    MezzanineFiles = new List<string> { },
                    StorageConnectionString = storageAccountString,
                    WorkflowName = "",
                    TimeStampUTC = String.Format("{0:o}", DateTime.Now.ToUniversalTime()),
                    ControlFileUri = ""
                    };
                if (j.JobMediaFiles.Count > 0)
                {
                    var blob = new CloudBlockBlob(j.JobMediaFiles[0]);
                    message.WorkflowName = blob.Container.Name;
                }
                foreach (Uri blobUri in j.JobMediaFiles)
                {
                    message.MezzanineFiles.Add(blobUri.ToString());
                }

                if (j.JobControlFile != null)
                {
                    message.ControlFileUri = j.JobControlFile.ToString();
                }

                CloudQueueMessage butlerRequestMessage = new CloudQueueMessage(JsonConvert.SerializeObject(message));
                sendQueue.AddMessageAsync(butlerRequestMessage);
            }
            catch (Exception)
            {

                throw;
            }

            return j.JobId;
        }