Perl: how to wait for a curl step to finish before processing to the next

Emily :

How does perl wait for a step before processing the next step?

e.g.

I have a command (checking status of the pervious data uploading step):

curl -H "Content-Type: application/json" -H "Authorization: Bearer DS_12345" -X GET https://api.xxx

The response is:

{
  "method":"a",
  "users":["[email protected] "],
  "status":"DONE",
  "export-url":"https://api.xxx/v1/export/DP_6789xxx"
}

The status can be: "DONE", "FAIL" or "PROCESSING". When the status is "PROCESSING", I don't want to quit the program and run it again. Instead, I want to wait until the status is "DONE" and then go for the next step, by taking response "export-url":"https://api.xxx/v1/export/DP_6789xxx"from the previous step. (when it's "FAIL", report and exit)

curl -H "Content-Type: application/json" -H "Authorization: Bearer DS_12345" -X GET https://api.xxx/v1/export/DP_6789xxx?view=xml

Thank you for your reply.

choroba :

Use a while loop:

my $result = 'PROCESSING';
while ($result eq 'PROCESSING') {
    my $response = ... # 
    $result = $response->{status};
    sleep 5;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=220234&siteId=1