3 Replies Latest reply: Oct 30, 2018 3:13 PM by Chung Lee RSS

    When using DataWatch API, the GetStatus() method does not give correct status

    Chung Lee

      I used the DataWatch API to call the DataWatch process from a .NET program. I could call the correct process but I could not get the correct status from after the process is called.  I think it's because the GetStatus method does not wait for the StartProcess() method to finish.

       

      I used the following code, I had to use Thread.Sleep to pause to get the status but then it is not reliable.  Is there any other way to get the correct status? I need to pass the status to the calling program to show whether the call is a success or failure.

       

      Thanks for you help!

      if (m_bLocal)
                              strTrackingID = PumpAPI.StartProcess(processName);
                          else
                          {
                

                              strTrackingID = WebService.StartProcess(processName);
                             
                              System.Threading.Thread.Sleep(2000);
                              int response = WebService.GetStatus(strTrackingID);
                              switch (response)
                              {
                                  case 2:
                                      jobStatus = true;
                                      break;
                                  case 3:
                                      jobStatus = false;
                                      break;
                                  default:
                                      jobStatus = false;
                                      break;
                              }
                          }

        • Re: When using DataWatch API, the GetStatus() method does not give correct status
          Chris Porthouse

          Not sure I understand what you mean by correct status.  What responses are you getting back?  I would suggest you break out the code into a separate function to check the status, or place it in a while loop until your condition is met (pass/fail).  Depending on the process you are running, it could take several minutes for that process to complete, so you will need to constantly get the job status.  If you do you want to wait for the process to finish, I would recommend the while loop with a thread.sleep(5000) so you only send a request for status every 5 seconds.

          • Re: When using DataWatch API, the GetStatus() method does not give correct status
            Mo Abdolrahim

            Hi Chung,

            I suggest you run the sample .NET C# program and see how it is being done in that sample.

            In additional to the sample example, you may try the following;

            // the second number is the job ordinal number, and starts from 1.  If your process has two job, then the first one have a ordinal number of 1

            // and the second one has an ordinal number of 2

            // if job has not been submitted, then the GetJobId method will be undefined and may throw an exception.  You may check for the exception and call the

            // GetJobId again or sleep for a few seconds before calling the GetJobId method.

            System.Threading.Thread.Sleep(2000);

            int iJobId = WebService.GetJobId(strTrackingId,1);

            // the GetJobStatus method will return the status of the job

            // Status Code Description

            // 0 Registered. This is the intial status when a StartProcess is requested.

            // 1 ProcessReady. The process is ready to run.

            // 2 ProcessAwaitingRetry. The process is awaiting retry after a failed run attempt.

            // 3 ProcessFailed. The process failed and is not scheduled for retry.

            // 4 ProcessCancelled. The process was cancelled before jobs were launched.

            // 5 Ready. The job is ready to be dispatched.

            // 6 Running. The job is running.

            // 7 Completed. The job completed without errors.

            // 8 Failed. The job failed.

            // 9 Cancelled. The job was cancelled before completion.

            // 10 Deferred. The job was deferred while a parallel job is running.

            // 11 ProcessResolvingWebAddresses. The process is resolving Web addresses in a manifest.

            // 12 RunningPreProcessScript. The process is currently running its PreProcess script.

            int Response = WebService.GetJobStatus(strTrackingId, iJobId, "");

             

            Regards

            Mo

              • Re: When using DataWatch API, the GetStatus() method does not give correct status
                Chung Lee

                Hi Mo,

                 

                You are correct.  I have finished using the sample code and was able to call the Datapump process.  I also used the GetJobStatus method you suggested.  It works except that if I call the process a second time, I got the following error message

                 

                {"Server was unable to process request. ---> Automator job ordinal 1 in process 3d7099ad-f0e2-44f8-a2ba-01090a941e7a not found"}

                 

                I dispose the WebService object in every call and a new instance of the services is created in every call.  If I delete all the jobs in the Datapump Automator and run the process again, then I don’t get this error message. Do you know how this can be resolved?  The GetJobStatus method is useful because I can get the statusText output and pass on to the calling application.

                 

                Thanks for your help!

                 

                Chung