Question

Asynchronous Calls to FME Server and Polling for Job Completion

  • 13 October 2021
  • 4 replies
  • 22 views

Badge

Continuing work described in this previous thread, I would like to figure out how to make asynchronous calls to FME Server and poll the job until it's completed, then capture the response. That will allow me to communicate to user in the UI what's going in while job is running, rather than just be waiting for something go happen.

 

So far, I've switched from 

FMEServer.runWorkspaceWithData( repository, workspace, params, callback);

to

FMEServer.submitJob( repository, workspace, params, callback);

which returns the job ID. There are so many ways in Javascript to now poll the service to check if the job is complete... I was hoping someone has a concise snippet to share?! Maybe there is even a feature in the API or an FME example I've overlooked .  


4 replies

Userlevel 2
Badge +19

The FME Server API has a method where you can check the Job status:

 

https://docs.safe.com/fme/html/FME_REST/apidoc/v3/index.html#!/transformations/get_get_18

job1

Badge

@oscard​  - Thanks for the comment. I was hoping more for some JS snippet. As I indicated above, I can get the job ID, and then I can build the URL

http://<my-fme-machine-fqdn>/fmerest/v3/transformations/jobs/id/job-id

Then I can do some async/await in Javascript... trying that right now. But interestingly, when I request that above URL programmatically, I get a 401. When I type the URL in my browser, I get a JSON response for a failed job. Somehow I must be missing something about the asynchronous works differently. 

Badge

So this is what's happening? 401 Unauthorized Error When Making FME Server Request

I get the job ID using the FMEServer connection that I made using a token. Now, I'm trying to do something like ...

async function checkJobStatus(jobUrl) {
        const response = await fetch(jobUrl, {
        ...
    });
...
)};

Well, and  there are no credentials in there! How do I get some like the above to work with an FME token?

 

Badge

This seems to be doing the polling , as desired...

const response = await fetch(jobUrl, 
    {
         headers: {
         'Accept': 'application/json',
         'Authorization': 'fmetoken token= < my token > '
 }

But now, I'm getting an error with published parameters and the job fails because I'm not telling it what to do with the output anymore. Workspace is looking for the original (default) parameters as published to server. Probably have to tweak my params one more time...

Reply