Select to view content in your preferred language

GP Service - Result as Map Service *sometimes* fails

2157
1
Jump to solution
05-22-2014 11:58 AM
ErikMartin
Frequent Contributor
I have an asynchronous geoprocessing service which returns a raster result via a map service.  The GP service is fully functional -- I can run it via the REST endpoint or inside ArcMap with no problems. 

I developed a custom widget which sits inside the Flex Viewer (3.6) to allow user to pass the input parameters to the GP service and handle the result.  This setup is working for me most of the time.  I've run the GP service several times in a row with no problems -- the result is returned, displayed properly & all is well.   Other times, the result is not returned and I get a  this error: "faultCode:400 faultString:'Invalid or missing input parameters.' faultDetail:''".

To be clear, this is a geoprocessing result map service.  I can see  that the GP service completed successfully -- the event.jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED.  But the map service that is supposed to be created isn't always created.

As a workaround, I've gone through various iterations of trying to reload the map service and finally made an error handler that fires if the map service does not load.  It resubmits the GP Service requestObject and runs the whole thing again.  Sometimes it will work on the 2nd go round, other times it takes a a couple tries. 

I've tried inserting a 1 second pause (after STATUS_SUCCEEDED) before trying to load the map, but to no avail.  (This should also not be necessary since "getResultMapServiceLayer(jobId:String):ArcGISDynamicMapServiceLayer Creates and configures an ArcGISDynamicMapServiceLayer instance ready to be added to a Map."

I've pasted in the relevant code below.  Any thoughts or guidance would be much appreciated.
-Erik

   //fires when geoprocessor finishes.  retrives result data    protected function gp_jobCompleteHandler(event:GeoprocessorEvent):void    {     if (event.jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED)     {             statusArea.appendText("Retrieving results from server..." + "\n");      scenarioIterator += 1       resMapServ = gp.getResultMapServiceLayer(gp.submitJobLastResult.jobId)      resMapServ.name = "Scenario" + String(scenarioIterator)            if (resMapServ.loaded)      {       map.addLayer(resMapServ)      }      else      {       resMapServ.addEventListener(LayerEvent.LOAD, resMapServ_loadHandler, false, 0, true);       resMapServ.addEventListener(LayerEvent.LOAD_ERROR, resMapServ_loadErrorHandler, false, 0, true);              function resMapServ_loadHandler(event:LayerEvent):void       {       resMapServ.removeEventListener(LayerEvent.LOAD, resMapServ_loadHandler);       resMapServ.removeEventListener(LayerEvent.LOAD_ERROR, resMapServ_loadErrorHandler);       map.addLayer(resMapServ)       }             function resMapServ_loadErrorHandler(event:LayerEvent):void       {        Alert.show("There was a problem loading the result. \n The analysis is being re-run. \n Sorry for the inconvenience.\n" +event.fault.message)        gp.submitJob(requestObject);       }      }      }          else     {      var messages1:Array = event.jobInfo.messages;      var count1:int = messages1.length;      var index1:int = count1-4;      var message1:String = messages1[index1].description;      Alert.show("Geoprocessing Error:\n" + message1);     }    }
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ErikMartin
Frequent Contributor
In the end, adding a pause fixed this issue. Based on the documentation (as bolded above) this shouldn't be necessary, but it fixed the problem.



 protected function gp_jobCompleteHandler(event:GeoprocessorEvent):void
   {
    gpResEvent = event;
    if (event.jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED)
    { 
     
     statusArea.appendText("Retrieving results from server..." + "\n");
     scenarioIterator += 1
     
     //wait a bit before adding the result so map service has time to start
     trace("starting delay...")
     var Timer:uint = setTimeout(delay, 1000); 
     function delay():void {
      resMapServ =  gp.getResultMapServiceLayer(gp.submitJobLastResult.jobId)
      resMapServ.name = "Scenario" + String(scenarioIterator)
      trace("delayed!");
      clearInterval(Timer); //stops the function from being called again
     
      if (resMapServ){trace("successfully added")}
      else{trace("did not add")}
     
      
      if (resMapServ.loaded)
      {
       map.addLayer(resMapServ)
      }
      else  //this is the workaround to resubmit parameters if map doesn't load
      {
       resMapServ.addEventListener(LayerEvent.LOAD, resMapServ_loadHandler, false, 0, true);
       resMapServ.addEventListener(LayerEvent.LOAD_ERROR, resMapServ_loadErrorHandler, false, 0, true);
       
       function resMapServ_loadHandler(event:LayerEvent):void
       {
       resMapServ.removeEventListener(LayerEvent.LOAD, resMapServ_loadHandler);
       resMapServ.removeEventListener(LayerEvent.LOAD_ERROR, resMapServ_loadErrorHandler);
       map.addLayer(resMapServ)
       }
      
       function resMapServ_loadErrorHandler(event:LayerEvent):void
       {
        Alert.show("There was a problem loading the result. \n JOBID " + gp.submitJobLastResult.jobId + "\n The analysis is being re-run. \n Sorry for the inconvenience.\n" +event.fault.message)
        gp.submitJob(requestObject);
       }
      }  
     }
    }
    
    else
    {
     var messages1:Array = event.jobInfo.messages;
     var count1:int = messages1.length;
     var index1:int = count1-4;
     var message1:String = messages1[index1].description;
     Alert.show("Geoprocessing Error:\n" + message1);
    }
   }

View solution in original post

0 Kudos
1 Reply
ErikMartin
Frequent Contributor
In the end, adding a pause fixed this issue. Based on the documentation (as bolded above) this shouldn't be necessary, but it fixed the problem.



 protected function gp_jobCompleteHandler(event:GeoprocessorEvent):void
   {
    gpResEvent = event;
    if (event.jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED)
    { 
     
     statusArea.appendText("Retrieving results from server..." + "\n");
     scenarioIterator += 1
     
     //wait a bit before adding the result so map service has time to start
     trace("starting delay...")
     var Timer:uint = setTimeout(delay, 1000); 
     function delay():void {
      resMapServ =  gp.getResultMapServiceLayer(gp.submitJobLastResult.jobId)
      resMapServ.name = "Scenario" + String(scenarioIterator)
      trace("delayed!");
      clearInterval(Timer); //stops the function from being called again
     
      if (resMapServ){trace("successfully added")}
      else{trace("did not add")}
     
      
      if (resMapServ.loaded)
      {
       map.addLayer(resMapServ)
      }
      else  //this is the workaround to resubmit parameters if map doesn't load
      {
       resMapServ.addEventListener(LayerEvent.LOAD, resMapServ_loadHandler, false, 0, true);
       resMapServ.addEventListener(LayerEvent.LOAD_ERROR, resMapServ_loadErrorHandler, false, 0, true);
       
       function resMapServ_loadHandler(event:LayerEvent):void
       {
       resMapServ.removeEventListener(LayerEvent.LOAD, resMapServ_loadHandler);
       resMapServ.removeEventListener(LayerEvent.LOAD_ERROR, resMapServ_loadErrorHandler);
       map.addLayer(resMapServ)
       }
      
       function resMapServ_loadErrorHandler(event:LayerEvent):void
       {
        Alert.show("There was a problem loading the result. \n JOBID " + gp.submitJobLastResult.jobId + "\n The analysis is being re-run. \n Sorry for the inconvenience.\n" +event.fault.message)
        gp.submitJob(requestObject);
       }
      }  
     }
    }
    
    else
    {
     var messages1:Array = event.jobInfo.messages;
     var count1:int = messages1.length;
     var index1:int = count1-4;
     var message1:String = messages1[index1].description;
     Alert.show("Geoprocessing Error:\n" + message1);
    }
   }

0 Kudos