From 9e9cb5e862e38d21f001f344066c0bb4e6ba35c0 Mon Sep 17 00:00:00 2001 From: Cassie Coyle Date: Mon, 7 Oct 2024 15:17:08 -0500 Subject: [PATCH] Fix jobs api decoding (#1097) * fix http ex Signed-off-by: Cassandra Coyle * rm decode Signed-off-by: Cassandra Coyle --------- Signed-off-by: Cassandra Coyle --- .github/env/global.env | 2 +- jobs/go/http/README.md | 2 +- jobs/go/http/job-service/job-service.go | 11 +---------- jobs/go/sdk/job-service/job-service.go | 12 ++++-------- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/.github/env/global.env b/.github/env/global.env index 1c50757ba..4207165ed 100644 --- a/.github/env/global.env +++ b/.github/env/global.env @@ -1,5 +1,5 @@ DAPR_CLI_VERSION: 1.14.1 -DAPR_RUNTIME_VERSION: 1.14.2 +DAPR_RUNTIME_VERSION: 1.14.4 DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v${DAPR_CLI_VERSION}/install/ DAPR_DEFAULT_IMAGE_REGISTRY: ghcr MACOS_PYTHON_VERSION: 3.10 diff --git a/jobs/go/http/README.md b/jobs/go/http/README.md index 0c71fb989..67233bab8 100644 --- a/jobs/go/http/README.md +++ b/jobs/go/http/README.md @@ -99,7 +99,7 @@ curl -X POST \ }, "dueTime": "2s" }' - ``` + ``` Back at the `job-service` app terminal window, the output should be: diff --git a/jobs/go/http/job-service/job-service.go b/jobs/go/http/job-service/job-service.go index 0eca44437..a439ed08c 100644 --- a/jobs/go/http/job-service/job-service.go +++ b/jobs/go/http/job-service/job-service.go @@ -14,7 +14,6 @@ limitations under the License. package main import ( - "encoding/base64" "encoding/json" "fmt" "io" @@ -65,16 +64,8 @@ func handleJob(w http.ResponseWriter, r *http.Request) { return } - // Decoding job data - decodedValue, err := base64.RawStdEncoding.DecodeString(jobData.Value) - if err != nil { - fmt.Printf("Error decoding base64: %v", err) - http.Error(w, fmt.Sprintf("error decoding base64: %v", err), http.StatusBadRequest) - return - } - // Creating Droid Job from decoded value - droidJob := setDroidJob(string(decodedValue)) + droidJob := setDroidJob(jobData.Value) fmt.Println("Starting droid:", droidJob.Droid) fmt.Println("Executing maintenance job:", droidJob.Task) diff --git a/jobs/go/sdk/job-service/job-service.go b/jobs/go/sdk/job-service/job-service.go index 82353a00d..4c76ca1a6 100644 --- a/jobs/go/sdk/job-service/job-service.go +++ b/jobs/go/sdk/job-service/job-service.go @@ -14,22 +14,21 @@ limitations under the License. package main /* -dapr run --app-id maintenance-scheduler --app-port 5200 --dapr-http-port 5280 --dapr-grpc-port 5281 --scheduler-host-address=127.0.0.1:50006 -- go run . +dapr run --app-id job-service --app-port 6400 --dapr-grpc-port 6481 --app-protocol grpc -- go run . */ import ( "context" - "encoding/base64" "encoding/json" "errors" "fmt" "log" "os" - "github.com/dapr/go-sdk/service/common" "google.golang.org/protobuf/types/known/anypb" daprc "github.com/dapr/go-sdk/client" + "github.com/dapr/go-sdk/service/common" daprs "github.com/dapr/go-sdk/service/grpc" ) @@ -205,12 +204,9 @@ func handleJob(ctx context.Context, job *common.JobEvent) error { if err := json.Unmarshal(job.Data, &jobData); err != nil { return fmt.Errorf("failed to unmarshal job: %v", err) } - decodedPayload, err := base64.StdEncoding.DecodeString(jobData.Value) - if err != nil { - return fmt.Errorf("failed to decode job payload: %v", err) - } + var jobPayload JobData - if err := json.Unmarshal(decodedPayload, &jobPayload); err != nil { + if err := json.Unmarshal(job.Data, &jobPayload); err != nil { return fmt.Errorf("failed to unmarshal payload: %v", err) }