Script to wait for a particular status from a response

Hi All,

Can someone please help me find out a sample code for waiting a particular status from a response?

Example:
My API response has a value like (“status”:“processing”) and then after 5 to 10secs the status changes to (“status”:“completed”).

Any sample code available to capture the status and wait for it to complete before triggering to next iterations?

Is it a HTTP API? If so, HTTP is stateless so I suppose you would need to poll the API until the status changes.

If it’s not a HTTP API then the solution may differ.

Hi @jabastinp
You could try a poll function that verifies if your previous request has the results you want it to have.
Hope this helps!

 let addAssetToQueue = http.post(`${__ENV.URL}/assets/queuedownload`, JSON.stringify(body), params);
    
    let start = Date.now();
    downloadKey = addAssetToQueue.json()['downloadKey']
   
    console.log('Download key: ' + downloadKey)

    function pollForPresignedUrl () {
        params = {
            headers : header,
            tags: {name: "poll for presigned url"},
        }

        let downloadFromQueue = http.get(`${__ENV.URL}/downloadfromqueue/${downloadKey}`, params)
        var status = downloadFromQueue.json()['status'] === 'done'

        if (status) {
            console.log('START '+ "VU USER " +__VU  + 'Iteration ' + __ITER + 'Date time ' + utcStr)
            console.log('DONE with polling, url stored.')
            
            presigned = downloadFromQueue.json()['assets'][0]['presigned_url']
            serverWaitingTimeToDownloadQueuedAsset.add(Date.now() - start);
            
            return this

        } else {
            console.log('START '+ " VU USER " +__VU  + ' Iteration ' + __ITER + ' Date time ' + utcStr)
            console.log('Still polling for presigned URL... ')

            sleep(0.2); 

            pollForPresignedUrl();
        }
    }
    pollForPresignedUrl();