use of com.amazonaws.services.simpleworkflow.model.RespondActivityTaskFailedRequest in project aws-doc-sdk-examples by awsdocs.
the class ActivityWorkerWithGracefulShutdown method pollAndExecute.
public static void pollAndExecute() {
while (!terminate) {
System.out.println("Polling for an activity task from the tasklist '" + HelloTypes.TASKLIST + "' in the domain '" + HelloTypes.DOMAIN + "'.");
ActivityTask task = swf.pollForActivityTask(new PollForActivityTaskRequest().withDomain(HelloTypes.DOMAIN).withTaskList(new TaskList().withName(HelloTypes.TASKLIST)));
String taskToken = task.getTaskToken();
if (taskToken != null) {
String result = null;
Throwable error = null;
try {
System.out.println("Executing the activity task with input '" + task.getInput() + "'.");
result = executeActivityTask(task.getInput());
} catch (Throwable th) {
error = th;
}
if (error == null) {
System.out.println("The activity task succeeded with result '" + result + "'.");
swf.respondActivityTaskCompleted(new RespondActivityTaskCompletedRequest().withTaskToken(taskToken).withResult(result));
} else {
System.out.println("The activity task failed with the error '" + error.getClass().getSimpleName() + "'.");
swf.respondActivityTaskFailed(new RespondActivityTaskFailedRequest().withTaskToken(taskToken).withReason(error.getClass().getSimpleName()).withDetails(error.getMessage()));
}
}
}
}
Aggregations