diff --git a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/api/JobReference.java b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/api/JobReference.java index 493e2b9f2..8d858b2ed 100644 --- a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/api/JobReference.java +++ b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/api/JobReference.java @@ -1,4 +1,13 @@ package org.webpieces.googlecloud.cloudtasks.api; public class JobReference { + private String taskId; + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } } diff --git a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/QueueInvokeHandler.java b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/QueueInvokeHandler.java index dcd49038f..0e90d18b2 100644 --- a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/QueueInvokeHandler.java +++ b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/QueueInvokeHandler.java @@ -3,6 +3,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.webpieces.ctx.api.HttpMethod; +import org.webpieces.googlecloud.cloudtasks.api.JobReference; import org.webpieces.googlecloud.cloudtasks.api.RemoteInvoker; import org.webpieces.googlecloud.cloudtasks.api.ScheduleInfo; import org.webpieces.microsvc.impl.EndpointInfo; diff --git a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/RemoteInvokerImpl.java b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/RemoteInvokerImpl.java index 6f2970638..9132500a4 100644 --- a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/RemoteInvokerImpl.java +++ b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/RemoteInvokerImpl.java @@ -1,8 +1,10 @@ package org.webpieces.googlecloud.cloudtasks.impl; import org.webpieces.ctx.api.HttpMethod; +import org.webpieces.googlecloud.cloudtasks.api.JobReference; import org.webpieces.googlecloud.cloudtasks.api.RemoteInvoker; import org.webpieces.googlecloud.cloudtasks.api.ScheduleInfo; +import org.webpieces.util.context.Context; import org.webpieces.util.futures.XFuture; import java.net.InetSocketAddress; @@ -11,6 +13,9 @@ public class RemoteInvokerImpl implements RemoteInvoker { @Override public XFuture invoke(InetSocketAddress addr, String path, HttpMethod httpMethod, String bodyAsText, ScheduleInfo info) { + JobReference ref = (JobReference) Context.get("webpieces-scheduleResponse"); + //fill in ref.setTaskId() + return null; } } diff --git a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/SchedulerImpl.java b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/SchedulerImpl.java index decc8a8da..22f79b9cc 100644 --- a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/SchedulerImpl.java +++ b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/impl/SchedulerImpl.java @@ -24,7 +24,8 @@ public XFuture addToQueue(Supplier> runnable) { private XFuture executeIt(Supplier> runnable, ScheduleInfo info) { Context.put("webpieces-scheduleInfo", info); - + //response to be filled in..... + Context.put("webpieces-scheduleResponse", new JobReference()); XFuture future = runnable.get(); return future.thenApply(v -> { JobReference reference = Context.get("webpieces-scheduleResponse"); diff --git a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/localimpl/HttpClientWrapper.java b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/localimpl/HttpClientWrapper.java index 35bb96059..b27ff2dde 100644 --- a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/localimpl/HttpClientWrapper.java +++ b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/localimpl/HttpClientWrapper.java @@ -254,7 +254,7 @@ private String unmarshal(String jsonReq, Contexts contexts, FullRequest request, log.info("unmarshalling response json='" + contents + "' http=" + httpResp.getHeaders() + " from request="+jsonReq+" to " + url); if (httpResp.getHeaders().getKnownStatusCode() == StatusCode.HTTP_200_OK) { - throw new UnsupportedOperationException("fix this later"); + return contents; } String message = "\njson error='" + contents + "' fullResp=" + httpResp + " url='" + url + "' originalRequest="+jsonReq; diff --git a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/localimpl/LocalRemoteInvoker.java b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/localimpl/LocalRemoteInvoker.java index be4c1b329..4cc59ccca 100644 --- a/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/localimpl/LocalRemoteInvoker.java +++ b/googlecloud/cloud-tasks/src/main/java/org/webpieces/googlecloud/cloudtasks/localimpl/LocalRemoteInvoker.java @@ -3,6 +3,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.webpieces.ctx.api.HttpMethod; +import org.webpieces.googlecloud.cloudtasks.api.JobReference; import org.webpieces.googlecloud.cloudtasks.api.RemoteInvoker; import org.webpieces.googlecloud.cloudtasks.api.ScheduleInfo; import org.webpieces.util.context.Context; @@ -11,6 +12,7 @@ import javax.inject.Inject; import java.net.InetSocketAddress; import java.util.Map; +import java.util.UUID; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -30,6 +32,12 @@ public LocalRemoteInvoker(HttpClientWrapper client) { @Override public XFuture invoke(InetSocketAddress addr, String path, HttpMethod httpMethod, String bodyAsText, ScheduleInfo info) { Map copy = Context.copyContext(); + JobReference ref = (JobReference) copy.get("webpieces-scheduleResponse"); + String jobId = UUID.randomUUID().toString(); + ref.setTaskId(jobId); + + //TODO: implement Map and map jobId to scheduled task to allow deletion of tasks as well. + if(info.isScheduledInFuture()) { executorService.schedule( () -> pretendToBeCallFromGCPCloudTasks(copy, addr, path, httpMethod, bodyAsText),