none
Problem while waiting QueueUpgradeProject to end RRS feed

  • Question

  • Hi,

    I have Project Server 2007 installed.

    I've created custom functionality which calls QueueUpgradeProject. One of my requirenments was to wait while this method ends. This method do not return jobUid so i was forced to implement more complicated solution to wait until task is done.

    Here is code:

    public static void WaitForUpgradeJob(DateTime from, DateTime to, int maxWaitTime, int minWaitTime)
            {
                var currWaitTime = 0;
                var end = false;
                //
                //
                //
                var q = GetClient();
                do
                {
                    var d = q.ReadMyJobStatus(new[] { QueueMsgType.LWPUpgradeToProject },
                                              new[]
                                                  {
                                                      JobState.Sleeping,
                                                      JobState.ReadyForProcessing,
                                                      JobState.ReadyForLaunch,
                                                      JobState.ProcessingDeferred,
                                                      JobState.Processing,
                                                      JobState.OnHold
                                                  }, from, to,
                                              0, true, SortColumn.CorrelationGUID, SortOrder.Ascending);
                    if (d.Status.Count == 0)
                    {
                        end = true;
                        continue;
                    }
                    var waitTime = minWaitTime +
                                   d.Status.Rows.Cast<DataRow>().Aggregate(0,
                                                                           (x, t) =>
                                                                           x + (int)t[d.Status.WaitTimeColumn] * 1000);
                    Thread.Sleep(waitTime);
                    currWaitTime += waitTime;
                    if (currWaitTime > maxWaitTime)
                        throw new Exception("Wait time exceeded allowable limit");
                } while (!end);
            }

    maxWaitTime and minWaitTime are configuration values.

    from and to values i get as follows:

    var from = DateTime.Now;
    projectService.QueueUpgradeProject(projUid);
    var to = DateTime.Now.AddSeconds(1);
    WaitForUpgradeJob(from,to,maxWaitTime,minWaitTime);

    This code worked for a long time. But last week i've encountered strange problem - after WaitForUpgradeJob method ends (no exception) i read project which was converted again and check his type to be sure that project really was converted. Last week this check started to fail - it was saying that project type is still Proposal. But in Project Server Queue i can see that all jobs finished without errors and there is no errors in ULS logs.

    The strange thing that i noticed is that time when WaitForUpgradeJob ends and time in column "End time" for task for converted project with job type "Project Proposal Upgrade" are different. For example, in my application logs i can see that WaitForUpgradeJob ended at 10:05:37, in Project Server Queue i can see that job with type "Project Proposal Upgrade" for converted project ended at 10:06 (there is no seconds).

    Any ideas what can be cause of this problem?


    Best regards, Chernobrivets

    Monday, October 8, 2012 7:23 AM

Answers

  • 1. As far as you deal with a specific project (and project UID is known) i would use ReadProjectJobStatus instead of common ReadMyJobStatus

    2. Think it is better to rely on job state (not on the time) like this

     if (jobState == SvcQueueSystem.JobState.Success)
                    {
                        jobIsDone = true;
                    }
                    else if (jobState == SvcQueueSystem.JobState.Unknown
                        || jobState == SvcQueueSystem.JobState.Failed
                        || jobState == SvcQueueSystem.JobState.FailedNotBlocking
                        || jobState == SvcQueueSystem.JobState.CorrelationBlocked
                        || jobState == SvcQueueSystem.JobState.Canceled)
                    {
                        stopWait = true;
                    }


    Sergey Vdovin

    • Marked as answer by Chernobrivec Wednesday, October 10, 2012 3:39 PM
    Tuesday, October 9, 2012 9:59 PM

All replies

  • Can someone provide me with feedback on my wait method? Maybe it has errors?

    Best regards, Chernobrivets


    Tuesday, October 9, 2012 8:27 AM
  • 1. As far as you deal with a specific project (and project UID is known) i would use ReadProjectJobStatus instead of common ReadMyJobStatus

    2. Think it is better to rely on job state (not on the time) like this

     if (jobState == SvcQueueSystem.JobState.Success)
                    {
                        jobIsDone = true;
                    }
                    else if (jobState == SvcQueueSystem.JobState.Unknown
                        || jobState == SvcQueueSystem.JobState.Failed
                        || jobState == SvcQueueSystem.JobState.FailedNotBlocking
                        || jobState == SvcQueueSystem.JobState.CorrelationBlocked
                        || jobState == SvcQueueSystem.JobState.Canceled)
                    {
                        stopWait = true;
                    }


    Sergey Vdovin

    • Marked as answer by Chernobrivec Wednesday, October 10, 2012 3:39 PM
    Tuesday, October 9, 2012 9:59 PM
  • Hi,

    Thank you for your answer.

    1. I didn't see this method before. Ill try it.

    2. You mean not to use from and to variables?


    Best regards, Chernobrivets


    • Edited by Chernobrivec Wednesday, October 10, 2012 8:19 AM
    Wednesday, October 10, 2012 8:17 AM
  • Yes.

    It is better to calc wait time in the code itself like it is in example.


    Sergey Vdovin

    Wednesday, October 10, 2012 11:05 AM
  • Wait time is calculated in my code.

    Variables from and to are used to call web service method.

    ReadProjectJobStatus method also requires this parameters.


    Best regards, Chernobrivets

    Wednesday, October 10, 2012 12:10 PM
  • here in calculation you get the time from the information about a job

    d.Status.Rows.Cast<DataRow>().Aggregate(0,
                                                                           (x, t) =>
                                                                           x + (int)t[d.Status.WaitTimeColumn] * 1000);


    Sergey Vdovin

    Wednesday, October 10, 2012 12:13 PM
  • Sorry, i dont fully understand what do you mean - i have wait time calculation in my code.

    Best regards, Chernobrivets

    Wednesday, October 10, 2012 3:38 PM