Esri Leaflet GP task callback ID not refreshing

4029
4
05-04-2016 01:04 AM
Labels (1)
FC_Basson
MVP Regular Contributor


I'm running a GP task through the Leaflet-Esri API which returns polygon geometries.  I then union these geometries with the standard ArcGIS Server Geometry utilities through a L.esri.request process and the union result must then be used in a final Leaflet GP task process, which is asynchronous and using CORS to force a POST request.  The problem is that the final GP Task call does not "detect" the task result (a URL string to a JSON file), even though I can see it being returned in the browser XHR requests and the result is in the ArcGIS Server GP jobs folder.  The one issue that I've picked up is that after the Union task, the callback ID for the last GP task does not increment again and I suspect that the Leaflet API is trying to fetch some of the previous GP tasks' results.  Is there a way to "reset" the callback ID for the GP task results to ensure that the API is trying to fetch the correct GP task results.

 

Here is the code for the final GP task call:

var gpServiceTest = L.esri.GP.service({      
      url: myGPserviceURL,
      path: "submitJob",
      async:true,
      asyncInterval:5,
      useCors:true
   });

   var gpTaskTest = gpServiceTest.createTask();
   gpTaskTest.setParam("Input_Polygon_String", rings);
   gpTaskTest.setOutputParam('JSON_Features');
   gpTaskTest.run(function(error, response, raw) {
         loadjson(response.JSON_Features.url);
   });

 

I've found that when I take the polygon results from the Union task and run the final GP task as an isolated function with it before any of the other initial GP tasks, there is no callback function ID added to the task results request.  However if I run the final GP task after the initial GP task and Union, a callback function ID, similar to a previous GP task result request callback ID, is added to the result request and that is when the response from the final GP task results give an error.

0 Kudos
4 Replies
FC_Basson
MVP Regular Contributor

It seems like the asynchronous CORS (post) request to the GP Service is not adding the Esri Leaflet callback function parameter to the async gp task messages returned from the service.

This is a screenshot of the XHR response strings when the final GP Service is run before any of the other gpservices in the app is initialised.  Note there is no callback function parameter in the URL, whereas my other GP tasks that run asynchronously do return a callback function parameter in the URL.

Screenshot of other GP task messages with callback function included in the URL

When I run the final GP service after the Esri Leaflet callback functions have been initiated, the async messages still have no callback function in the URL, but the final output parameter URL is specifying the same callback function as the task result above.

0 Kudos
FC_Basson
MVP Regular Contributor

The only (temporary) solution I have implemented is to change the final GP Service to a synchronous service and set the async parameter to false.  Now there is no conflict between the callback functions in the async URLs.

0 Kudos
JohnGravois
Deactivated User

honestly, im still trying to wrap my head around your question to determine the best course of action.

i'm 99% certain that its normal that only non CORS requests will attempt to wrap the response in a JS callback to get around cross-origin security restrictions. but i'll have to dig in deeper in order to determine why you're not able to get access to the results of the second GP task.

are the services that you're making calls to public?  either way, can you provide a simplified repro case?

0 Kudos
FC_Basson
MVP Regular Contributor

It is complicated to explain - sorry if I got you confused in my comments.  The core (or cors ) issue is that when I run the final GP task in a function with a polygon ring array as input parameter before any of the other non-CORS tasks, the output result URL does not contain a callback function, but when I run the final GP task after a non-CORS task, a callback function (exactly the same as in the last non-CORS task result output URL string) is added to the result output URL, but not the async messages URLs.  In both cases the final GP task result does reflect the correct value for the output parameter.

The services are public so I can share with you if you have time to take another look at it.   The app that I'm using it in is here: http://gis.elsenburg.com/apps/cdt/   After you have created two adjacent watersheds, run the hidden "union()" function.

0 Kudos