QueueSystem.GetJobWaitTime 方法
計算預期的剩餘處理 Project Server 佇列服務中的指定之的工作的時間量。
命名空間: WebSvcQueueSystem
組件: ProjectServerServices (在 ProjectServerServices.dll 中)
語法
'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/QueueSystem/GetJobWaitTime", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/QueueSystem/", _
ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/QueueSystem/", _
Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function GetJobWaitTime ( _
jobID As Guid _
) As Integer
'用途
Dim instance As QueueSystem
Dim jobID As Guid
Dim returnValue As Integer
returnValue = instance.GetJobWaitTime(jobID)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/QueueSystem/GetJobWaitTime", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/QueueSystem/",
ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/QueueSystem/",
Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public int GetJobWaitTime(
Guid jobID
)
參數
jobID
類型:System.Guid佇列工作的 GUID。
傳回值
類型:System.Int32
剩餘的秒數等候時間。
備註
預期的工作的等待時間才大約,根據類似類型的工作的平均等待時間。GetJobWaitTime還需考慮工作已在佇列和工作相互關聯優先順序的位置。
Project Server 權限
其中一個下列權限,則需要。
權限 |
描述 |
---|---|
非標準 |
目前的使用者是工作擁有者。 |
可讓使用者管理 Project Server 佇列。通用權限。 |
範例
For another example of a QueueSystem utility class, see How to: Use the QueueSystem Service.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Threading;
namespace SomeNamespace
{
class QueueSystemUtils
{
// Wait 2 seconds between each check for job completion.
private const int INCREMENTALSLEEPTIME = 2;
public QueueSystemUtils()
{
}
/// <summary>
/// Wait a specified time for the Project Server Queuing service to process a job.
/// </summary>
/// <param name="q">QueueSystem object</param>
/// <param name="timeOut">Maximum time to wait (seconds)</param>
/// <param name="jobId">GUID of queue job</param>
/// <param name="errorString">out: error from GetJobCompletionState plus status</param>
/// <returns>true for success; false for any queue failure</returns>
public bool WaitForQueue(WebSvcQueueSystem.QueueSystem q,
int timeOut,
Guid jobId,
out String statusOut)
{
int wait; // Number of seconds to wait
decimal seconds; // For reporting wait time in decimal format
string xmlError; // XML error output from the queue
string queueStatus; // Outer XML of xmlError string
string status = ""; // Summary status report for output
bool firstPass = true; // First iteration through the while statement
int timeSlept = 0; // Total time slept (seconds)
bool jobIsDone = false; // The queue job completed successfully, if true
bool stopWait = false; // Abort the wait, if true
WebSvcQueueSystem.JobState jobState; // Status of the queue job
while (true)
{
// On the first iteration, wait the incremental sleep time
// or the maximum requested timeout.
if (firstPass)
{
// Get the estimated time to wait for the queue to process the job.
// The output from GetJobWaitTime is in seconds.
wait = q.GetJobWaitTime(jobId);
status = string.Format("Estimated job wait time: {0} seconds", wait);
if (timeOut < INCREMENTALSLEEPTIME) wait = timeOut;
else wait = INCREMENTALSLEEPTIME;
firstPass = false;
}
else
{
// If job is not done, wait the incremental sleep time
wait = INCREMENTALSLEEPTIME;
}
Thread.Sleep(wait * 1000); // Milliseconds
timeSlept += wait;
// Check job state.
jobState = q.GetJobCompletionState(jobId, out xmlError);
// Add the XML error output to the status.
StringReader sr = new StringReader(xmlError);
using (XmlReader reader = XmlReader.Create(sr))
{
reader.MoveToContent();
queueStatus = reader.ReadOuterXml();
}
// Don't add an empty <errinfo> element.
if (queueStatus != "<errinfo />") status += "\n\n" + queueStatus;
if (jobState == WebSvcQueueSystem.JobState.Success)
{
jobIsDone = true;
}
else if (jobState == WebSvcQueueSystem.JobState.Unknown
|| jobState == WebSvcQueueSystem.JobState.Failed
|| jobState == WebSvcQueueSystem.JobState.FailedNotBlocking
|| jobState == WebSvcQueueSystem.JobState.CorrelationBlocked
|| jobState == WebSvcQueueSystem.JobState.Canceled)
{
stopWait = true;
}
if (!jobIsDone && timeSlept >= timeOut)
{
// Cancel the job, otherwise the queue keeps processing it until it is complete.
q.CancelJobSimple(jobId);
stopWait = true;
status += string.Format("\n\nExceeded timeout of {0} seconds", timeOut);
}
if (jobIsDone || stopWait)
{
// Check jobState again, might be cancelled.
seconds = Convert.ToDecimal(timeSlept);
status += string.Format(
"\n\nJobState: {0:G}\n\nTotal time slept: {1:N} seconds",
jobState, seconds);
break;
}
}
statusOut = status;
return jobIsDone;
}
}
}