use of com.google.cloud.tasks.v2.AppEngineHttpRequest in project workbench by all-of-us.
the class ForwardingCloudTasksStub method createTaskCallable.
@Override
public UnaryCallable<CreateTaskRequest, Task> createTaskCallable() {
return new UnaryCallable<CreateTaskRequest, Task>() {
@Override
public ApiFuture<Task> futureCall(CreateTaskRequest request, ApiCallContext context) {
final QueueName queueName = QueueName.parse(request.getParent());
final AppEngineHttpRequest gaeReq = request.getTask().getAppEngineHttpRequest();
final Request apiReq = new Request.Builder().url(baseUrl + gaeReq.getRelativeUri()).headers(Headers.of(gaeReq.getHeadersMap())).addHeader("X-AppEngine-QueueName", queueName.getQueue()).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), gaeReq.getBody().toStringUtf8())).build();
log.info(String.format("asynchronously forwarding task request for queue '%s', to handler '%s'", queueName.getQueue(), apiReq.url()));
OkHttpClient client = new OkHttpClient();
client.setReadTimeout(10, TimeUnit.MINUTES);
client.newCall(apiReq).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
log.log(Level.SEVERE, "task execution failed", e);
}
@Override
public void onResponse(Response response) {
}
});
return ApiFutures.immediateFuture(request.getTask());
}
};
}
Aggregations