Skip to content

Commit

Permalink
Fix jobs api decoding (#1097)
Browse files Browse the repository at this point in the history
* fix http ex

Signed-off-by: Cassandra Coyle <cassie@diagrid.io>

* rm decode

Signed-off-by: Cassandra Coyle <cassie@diagrid.io>

---------

Signed-off-by: Cassandra Coyle <cassie@diagrid.io>
  • Loading branch information
cicoyle authored Oct 7, 2024
1 parent bfb887e commit 9e9cb5e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/env/global.env
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion jobs/go/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ curl -X POST \
},
"dueTime": "2s"
}'
```
```

Back at the `job-service` app terminal window, the output should be:

Expand Down
11 changes: 1 addition & 10 deletions jobs/go/http/job-service/job-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ limitations under the License.
package main

import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions jobs/go/sdk/job-service/job-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 9e9cb5e

Please sign in to comment.