martes, 1 de abril de 2008

Queue functions

Looking in projectTool you can find the functions to control the end state of the jobs that you are sending to the queue.
Let's take a look to these functions.


1. Function wich checks if there is an error in the job

private static bool checkStatusRowHasError(string errorInfo)
{
System.Xml.XmlTextReader xReader = new System.Xml.XmlTextReader(new System.IO.StringReader(errorInfo));
while (xReader.Read()) {
if (xReader.Name == "errinfo" && xReader.NodeType == System.Xml.XmlNodeType.Element) {
xReader.Read(); if (xReader.Value == "")
return false;
else return true; }
}
return false; }

2. Function wich waits until the job has finished or timeout has reached.

private bool WaitForQueueJobCompletion(Guid linkId, int messageType, TaskGrid.QueueSystemDerived queueSystem) {

QueueSystem.QueueStatusDataSet queueStatusDataSet = new QueueSystem.QueueStatusDataSet();
QueueSystem.QueueStatusRequestDataSet queueStatusRequestDataSet = new QueueSystem.QueueStatusRequestDataSet();
QueueSystem.QueueStatusRequestDataSet.StatusRequestRow statusRequestRow = queueStatusRequestDataSet.StatusRequest.NewStatusRequestRow();
statusRequestRow.JobGUID = linkId;

3. Coments BUGBUG are from Microsoft Engineers :) Sometimes they leave us some feedback of the development process...

statusRequestRow.JobGroupGUID = Guid.NewGuid(); statusRequestRow.MessageType = -1; //BUGBUG - Rightnow lets just use -1 queueStatusRequestDataSet.StatusRequest.AddStatusRequestRow(statusRequestRow);
bool inProcess = true;
DateTime startTime = DateTime.Now; i
nt successState = (int)QueueConstants.JobState.Success; i
nt failedState = (int)QueueConstants.JobState.Failed;
int blockedState = (int)QueueConstants.JobState.CorrelationBlocked;
while (inProcess) { queueStatusDataSet = queueSystem.ReadJobStatus(queueStatusRequestDataSet, false, QueueSystem.SortColumn.Undefined, QueueSystem.SortOrder.Undefined);
foreach (QueueSystem.QueueStatusDataSet.StatusRow statusRow in queueStatusDataSet.Status)
{
if ((statusRow["ErrorInfo"] != System.DBNull.Value && checkStatusRowHasError(statusRow["ErrorInfo"].ToString()) == true) statusRow.JobCompletionState == blockedState statusRow.JobCompletionState == failedState)
{ ///Error en la cola
inProcess = false;
return false; }
if (statusRow.JobCompletionState == successState)
{ inProcess = false; return true; }
else { inProcess = true; System.Threading.Thread.Sleep(500); } }
DateTime endTime = DateTime.Now;
TimeSpan span = endTime.Subtract(startTime);
if (span.Seconds > 30) //Wait for only 20 secs - and then bail out.
{ ///Error en la cola
return false; } }
return true; }

No hay comentarios: