AWS IoT Device SDK C: Jobs
AWS IoT Jobs library
Return to main page ↑
AwsIotJobs_Wait

Wait for a Jobs operation to complete.

uint32_t timeoutMs,
AwsIotJobsResponse_t * const pJobsResponse );

This function blocks to wait for a GET PENDING, START NEXT, DESCRIBE, or UPDATE operation to complete. These operations are by default asynchronous; the function calls queue an operation for processing, and a callback is invoked once the operation is complete.

To use this function, the flag AWS_IOT_JOBS_FLAG_WAITABLE must have been set in the operation's function call. Additionally, this function must always be called with any waitable operation to clean up resources.

Regardless of its return value, this function always clean up resources used by the waitable operation. This means operation is invalidated as soon as this function returns, even if it returns AWS_IOT_JOBS_TIMEOUT or another error.

Parameters
[in]operationReference to the Jobs operation to wait for. The flag AWS_IOT_JOBS_FLAG_WAITABLE must have been set for this operation.
[in]timeoutMsHow long to wait before returning AWS_IOT_JOBS_TIMEOUT.
[out]pJobsResponseThe response received from the Jobs service.
Returns
One of the following:

Example:

#define THING_NAME "Test_device"
#define THING_NAME_LENGTH ( sizeof( THING_NAME ) - 1 )
// Set the request info.
requestInfo.mqttConnection = _mqttConnection;
requestInfo.pThingName = THING_NAME;
requestInfo.thingNameLength = THING_NAME_LENGTH;
// Set the function used to allocate memory for an incoming response.
requestInfo.mallocResponse = malloc;
// A Job ID must be set. AWS_IOT_JOBS_NEXT_JOB is not valid for UPDATE.
requestInfo.pJobId = "job-id";
requestInfo.jobIdLength = 6;
// Set the update info.
// Queue Jobs UPDATE.
AwsIotJobsError_t updateResult = AwsIotJobs_UpdateAsync( &requestInfo,
&updateInfo,
NULL,
&updateOperation );
// UPDATE should have returned AWS_IOT_JOBS_STATUS_PENDING. The call to wait
// returns once the result of the UPDATE is available or the timeout expires.
if( updateResult == AWS_IOT_JOBS_STATUS_PENDING )
{
updateResult = AwsIotJobs_Wait( updateOperation, 5000, &jobsResponse );
if( updateResult == AWS_IOT_JOBS_SUCCESS )
{
// Jobs operation succeeded. Do something with the Jobs response.
// Once the Jobs response is no longer needed, free it.
free( jobsResponse.pJobsResponse );
}
else
{
// Jobs operation failed.
}
}