Skip to content

Commit

Permalink
fix it so it returns successfully (#140)
Browse files Browse the repository at this point in the history
Co-authored-by: Dean Hiller <[email protected]>
  • Loading branch information
deanhiller and deantray authored Feb 13, 2023
1 parent d4e7413 commit 0ddf01a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +13,9 @@
public class RemoteInvokerImpl implements RemoteInvoker {
@Override
public XFuture<Void> invoke(InetSocketAddress addr, String path, HttpMethod httpMethod, String bodyAsText, ScheduleInfo info) {
JobReference ref = (JobReference) Context.get("webpieces-scheduleResponse");
//fill in ref.setTaskId()

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public XFuture<JobReference> addToQueue(Supplier<XFuture<Void>> runnable) {

private XFuture<JobReference> executeIt(Supplier<XFuture<Void>> runnable, ScheduleInfo info) {
Context.put("webpieces-scheduleInfo", info);

//response to be filled in.....
Context.put("webpieces-scheduleResponse", new JobReference());
XFuture<Void> future = runnable.get();
return future.thenApply(v -> {
JobReference reference = Context.get("webpieces-scheduleResponse");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -30,6 +32,12 @@ public LocalRemoteInvoker(HttpClientWrapper client) {
@Override
public XFuture<Void> invoke(InetSocketAddress addr, String path, HttpMethod httpMethod, String bodyAsText, ScheduleInfo info) {
Map<String, Object> 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),
Expand Down

0 comments on commit 0ddf01a

Please sign in to comment.