Skip to content

Commit

Permalink
Fix dump
Browse files Browse the repository at this point in the history
  • Loading branch information
alfred2g committed Nov 30, 2023
1 parent 9ef5508 commit b6d545c
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions servicetests/tests/JobsExecution/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char *argv[])
{

fprintf(stdout, "starting the jobs execution programm\n");
std::this_thread::sleep_for(std::chrono::seconds(10));
//std::this_thread::sleep_for(std::chrono::seconds(10));
/************************ Setup ****************************/

// Do the global initialization for the API
Expand Down Expand Up @@ -79,6 +79,7 @@ int main(int argc, char *argv[])
}
// Create Mqtt5Client
std::shared_ptr<Aws::Crt::Mqtt5::Mqtt5Client> client5;
IotJobsClient *jobsClient;
if (cmdData.input_mqtt_version == 5UL)
{
// Create the MQTT5 builder and populate it with data from cmdData.
Expand Down Expand Up @@ -122,6 +123,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "MQTT5 Connection failed to start");
exit(-1);
}
jobsClient = new IotJobsClient(client5);
}
else if (cmdData.input_mqtt_version == 3UL)
{
Expand Down Expand Up @@ -188,6 +190,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "MQTT Connection failed with error %s\n", ErrorDebugString(connection->LastError()));
exit(-1);
}
jobsClient = new IotJobsClient(connection);
}
else
{
Expand All @@ -198,12 +201,10 @@ int main(int argc, char *argv[])
delete builder;

/************************ Run the sample ****************************/

if (connectionCompletedPromise.get_future().get())
{
IotJobsClient jobsClient(connection);

getAvailableJobs(cmdData.input_thingName, jobsClient);
getAvailableJobs(cmdData.input_thingName, *jobsClient);
for (auto jobid : availableJobs)
{
DescribeJobExecutionSubscriptionRequest describeJobExecutionSubscriptionRequest;
Expand Down Expand Up @@ -235,7 +236,7 @@ int main(int argc, char *argv[])
}
};

jobsClient.SubscribeToDescribeJobExecutionAccepted(
jobsClient->SubscribeToDescribeJobExecutionAccepted(
describeJobExecutionSubscriptionRequest,
AWS_MQTT_QOS_AT_LEAST_ONCE,
subscriptionHandler,
Expand All @@ -261,7 +262,7 @@ int main(int argc, char *argv[])
}
};

jobsClient.SubscribeToDescribeJobExecutionRejected(
jobsClient->SubscribeToDescribeJobExecutionRejected(
describeJobExecutionSubscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, failureHandler, subAckHandler);
subAckedPromise.get_future().wait();

Expand All @@ -281,7 +282,7 @@ int main(int argc, char *argv[])
publishDescribeJobExeCompletedPromise.set_value();
};

jobsClient.PublishDescribeJobExecution(
jobsClient->PublishDescribeJobExecution(
std::move(describeJobExecutionRequest), AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler);
publishDescribeJobExeCompletedPromise.get_future().wait();

Expand Down Expand Up @@ -312,7 +313,7 @@ int main(int argc, char *argv[])
StartNextPendingJobExecutionSubscriptionRequest subscriptionRequest;
subscriptionRequest.ThingName = cmdData.input_thingName;
subAckedPromise = std::promise<void>();
jobsClient.SubscribeToStartNextPendingJobExecutionAccepted(
jobsClient->SubscribeToStartNextPendingJobExecutionAccepted(
subscriptionRequest,
AWS_MQTT_QOS_AT_LEAST_ONCE,
OnSubscribeToStartNextPendingJobExecutionAcceptedResponse,
Expand All @@ -321,7 +322,7 @@ int main(int argc, char *argv[])
subAckedPromise.get_future().wait();

subAckedPromise = std::promise<void>();
jobsClient.SubscribeToStartNextPendingJobExecutionRejected(
jobsClient->SubscribeToStartNextPendingJobExecutionRejected(
subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, failureHandler, subAckHandler);

subAckedPromise.get_future().wait();
Expand All @@ -331,7 +332,7 @@ int main(int argc, char *argv[])
publishRequest.StepTimeoutInMinutes = 15L;

publishDescribeJobExeCompletedPromise = std::promise<void>();
jobsClient.PublishStartNextPendingJobExecution(
jobsClient->PublishStartNextPendingJobExecution(
publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler);

pendingExecutionPromise.get_future().wait();
Expand All @@ -355,15 +356,15 @@ int main(int argc, char *argv[])
subscriptionRequest.JobId = currentJobId;

subAckedPromise = std::promise<void>();
jobsClient.SubscribeToUpdateJobExecutionAccepted(
jobsClient->SubscribeToUpdateJobExecutionAccepted(
subscriptionRequest,
AWS_MQTT_QOS_AT_LEAST_ONCE,
OnSubscribeToUpdateJobExecutionAcceptedResponse,
subAckHandler);
subAckedPromise.get_future().wait();

subAckedPromise = std::promise<void>();
jobsClient.SubscribeToUpdateJobExecutionRejected(
jobsClient->SubscribeToUpdateJobExecutionRejected(
subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, failureHandler, subAckHandler);
subAckedPromise.get_future().wait();

Expand All @@ -374,7 +375,7 @@ int main(int argc, char *argv[])
publishRequest.ExecutionNumber = currentExecutionNumber;
publishRequest.Status = JobStatus::IN_PROGRESS;
publishRequest.ExpectedVersion = currentVersionNumber++;
jobsClient.PublishUpdateJobExecution(publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler);
jobsClient->PublishUpdateJobExecution(publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler);

pendingExecutionPromise.get_future().wait();
}
Expand All @@ -399,12 +400,12 @@ int main(int argc, char *argv[])
pendingExecutionPromise.set_value();
};
subAckedPromise = std::promise<void>();
jobsClient.SubscribeToUpdateJobExecutionAccepted(
jobsClient->SubscribeToUpdateJobExecutionAccepted(
subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, subscribeHandler, subAckHandler);
subAckedPromise.get_future().wait();

subAckedPromise = std::promise<void>();
jobsClient.SubscribeToUpdateJobExecutionRejected(
jobsClient->SubscribeToUpdateJobExecutionRejected(
subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, failureHandler, subAckHandler);
subAckedPromise.get_future().wait();

Expand All @@ -416,7 +417,7 @@ int main(int argc, char *argv[])
publishRequest.ExpectedVersion = currentVersionNumber++;

publishDescribeJobExeCompletedPromise = std::promise<void>();
jobsClient.PublishUpdateJobExecution(publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler);
jobsClient->PublishUpdateJobExecution(publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler);

pendingExecutionPromise.get_future().wait();
}
Expand Down Expand Up @@ -462,15 +463,23 @@ void getAvailableJobs(Aws::Crt::String thingName, IotJobsClient &jobsClient)
{
fprintf(stderr, "Error %d occurred\n", ioErr);
}
for (JobExecutionSummary job : response->InProgressJobs.value())
{
availableJobs.push_back(job.JobId.value());
fprintf(stderr, "In Progress jobs %s\n", job.JobId->c_str());
}
for (JobExecutionSummary job : response->QueuedJobs.value())
{
availableJobs.push_back(job.JobId.value());
fprintf(stderr, "Queued jobs %s\n", job.JobId->c_str());
if (response) {
if (response->InProgressJobs.has_value())
{
for (JobExecutionSummary job : response->InProgressJobs.value())
{
availableJobs.push_back(job.JobId.value());
fprintf(stderr, "In Progress jobs %s\n", job.JobId->c_str());
}
}
if (response->QueuedJobs.has_value())
{
for (JobExecutionSummary job : response->QueuedJobs.value())
{
availableJobs.push_back(job.JobId.value());
fprintf(stderr, "Queued jobs %s\n", job.JobId->c_str());
}
}
}
getResponse.set_value();
};
Expand Down

0 comments on commit b6d545c

Please sign in to comment.