XPP Rest return values and order of operations

In javascript running on a content server, I am using axios.get to run an XPP Rest "User command," which successfully executes a Perl script on the XPP server to copy a file from one folder to another on that server. I am separately signed into the XPP server, and can see that the file has been copied successfully. On the javascript side, I am receiving status code 200 (success), which I think means that XPP Rest found the Perl script and ran it. Unfortunately, code 200 does not mean that the file copied successfully on the XPP server, because the Perl script fails silently when I ask it to copy a nonexistent file. I am looking for a way please to provide a meaningful return value from the Perl script back to the javascript, to verify that the file copy took place and therefore that subsequent actions can proceed. Thank you!

  • Well, in your perl, you could just check for existence of source file (before copying) and destination file (after copying) and if doesn't exist, exit with error code that javascript will also interpret as fail.

  • Thank you, Shawn, exiting the Perl with an error code (if the file copy return value indicates failure) seems to work!

    In the javascript, I believe that I have written the code correctly with promises to wait for a return value before moving on to the next function.  I make another User Command call after the first one, to perform a similar file copy function.  Observing the filetimes on the XPP side with "ls --full-time", it looks like the second file is copied a few milliseconds after the first, as expected.

    The next function call in the javascript is XPP RESTful function Put File, to copy a file from the content server to the XPP server.  Based on filetimes, the Put File appears to complete its file operation a few milliseconds before the second User Command file copy.  This seems to indicate that one or more file handling functions on the XPP side are asynchronous or returning positive values before the file operations are complete, or possibly, that the filetimes obtained with "ls --full-time" are not accurate.

    I could try to introduce additional checks or delays on the javascript side, though that would be less elegant.  I am open to suggestions for how to ensure the correct sequence of operations, thank you!

  • Peter,

    As is typical for a REST interface things run asynchronously. That is if you do 2 separate calls, the second call will not wait for the first call to end. They both run as independent processes. So there is no way of telling which one will complete first.
    If you want to stay in control, you have to set the "nowait=true" option on each of the calls.
    As the doc says: 
    If "nowait=true", the command will return immediately with the id, code, and time the command started (default="false"). The user can check for command completion, by using the 'xpp/docs/processes/id' endpoint;
    Checking the command status will return either 'running' or the exit code of the process you started.

  • Thank you, Bart!  After sending my previous message, with further testing I realized that the Linux command "ls --full-time" was showing me last-modified file times, not file creation times.  My implementation in javascript appears to be working so far.  Each RESTful call is wrapped in a function that returns a promise, the function calls have .then blocks that wait for the responses, and the next function call is embedded in the previous function's .then block.  I may still need to use nowait=true, we'll see!  Best regards, Peter

Reply Children