コード例 #1
0
        protected void WaitForJobComplete(QueueJob job, int?seconds = null)
        {
            try
            {
                DateTime startTime = DateTime.Now;
                int      waitTime  = seconds ?? 300;
                JobState jobState  = JobState.Unknown;
                do
                {
                    jobState = BaseProjectContext.WaitForQueue(job, 3);
                }while (jobState != JobState.Success && startTime.AddSeconds(waitTime) > DateTime.Now);

                if (jobState == JobState.Success)
                {
                    LoggerHelper.Instance.Pass(job.Id.ToString());
                }
                else
                {
                    LoggerHelper.Instance.Fail(string.Format("The job status is {0}.", jobState));
                }
            }
            catch (Exception e)
            {
                job.Cancel();
                LoggerHelper.Instance.Fail(string.Format("Warning: The job is failed.\nMessage: {0}. \nMore:{1} \nRetrying...", e.Message, e.StackTrace));
            }
        }
        public void UpdateProject(DraftProject draftProject, List <StagingDTO> affectedStagings)
        {
            if (draftProject == null)
            {
                return;
            }
            QueueJob job   = null;
            JobState state = JobState.Unknown;

            try
            {
                logger.LogAndSendMessage(null, "UpdateProject",
                                         draftProject.Id, winServiceIterationUid,
                                         $"UpdateProject Update {draftProject.Id}",
                                         false, null, CommonConstants.Epm, CommonConstants.Start);
                job = draftProject.Update();
                WaitForQueue(job, draftProject.Id, draftProject, out state);
                logger.LogAndSendMessage(null, "UpdateProject Update WaitForQueue",
                                         draftProject.Id, winServiceIterationUid,
                                         $"UpdateProject Update WaitForQueue {draftProject.Id}",
                                         false, null);
                if (state == JobState.Success)
                {
                    if (affectedStagings != null)
                    {
                        foreach (StagingDTO affectedStaging in affectedStagings)
                        {
                            affectedStaging.RecordStateGeneral = RecordStateConst.Updated;
                        }
                    }
                    else
                    {
                        logger.LogAndSendMessage(null, "UpdateProject Update WaitForQueue",
                                                 draftProject.Id, winServiceIterationUid,
                                                 $"UpdateProject 1 WaitForQueue job failed. Project UID: {draftProject.Id}; jobState: {state}",
                                                 true, null);
                    }
                }
                logger.LogAndSendMessage(null, "UpdateProject",
                                         draftProject.Id, winServiceIterationUid,
                                         $"UpdateProject END {draftProject.Id}",
                                         false, null, CommonConstants.Epm, CommonConstants.End);
            }
            catch (ServerException serverException)
            {
                logger.LogAndSendMessage(null, "UpdateProject",
                                         draftProject.Id, winServiceIterationUid,
                                         $"UpdateProject {draftProject.Id} JobState: {state}",
                                         false, serverException);
                try
                {
                    if (job != null)
                    {
                        job.Cancel();
                        ProjectContext.Load(job);
                        ExecuteQuery();
                    }
                }
                catch (Exception exception)
                {
                    logger.LogAndSendMessage(null, "UpdateProject Cancel",
                                             draftProject.Id, winServiceIterationUid,
                                             $"UpdateProject Cancel {draftProject.Id} JobState: {state}",
                                             false, exception);
                }
            }
        }