Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jobs api decoding #1097

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading