Skip to content

Commit 9e9cb5e

Browse files
authored
Fix jobs api decoding (#1097)
* fix http ex Signed-off-by: Cassandra Coyle <[email protected]> * rm decode Signed-off-by: Cassandra Coyle <[email protected]> --------- Signed-off-by: Cassandra Coyle <[email protected]>
1 parent bfb887e commit 9e9cb5e

File tree

4 files changed

+7
-20
lines changed

4 files changed

+7
-20
lines changed

.github/env/global.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DAPR_CLI_VERSION: 1.14.1
2-
DAPR_RUNTIME_VERSION: 1.14.2
2+
DAPR_RUNTIME_VERSION: 1.14.4
33
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v${DAPR_CLI_VERSION}/install/
44
DAPR_DEFAULT_IMAGE_REGISTRY: ghcr
55
MACOS_PYTHON_VERSION: 3.10

jobs/go/http/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ curl -X POST \
9999
},
100100
"dueTime": "2s"
101101
}'
102-
```
102+
```
103103

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

jobs/go/http/job-service/job-service.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ limitations under the License.
1414
package main
1515

1616
import (
17-
"encoding/base64"
1817
"encoding/json"
1918
"fmt"
2019
"io"
@@ -65,16 +64,8 @@ func handleJob(w http.ResponseWriter, r *http.Request) {
6564
return
6665
}
6766

68-
// Decoding job data
69-
decodedValue, err := base64.RawStdEncoding.DecodeString(jobData.Value)
70-
if err != nil {
71-
fmt.Printf("Error decoding base64: %v", err)
72-
http.Error(w, fmt.Sprintf("error decoding base64: %v", err), http.StatusBadRequest)
73-
return
74-
}
75-
7667
// Creating Droid Job from decoded value
77-
droidJob := setDroidJob(string(decodedValue))
68+
droidJob := setDroidJob(jobData.Value)
7869

7970
fmt.Println("Starting droid:", droidJob.Droid)
8071
fmt.Println("Executing maintenance job:", droidJob.Task)

jobs/go/sdk/job-service/job-service.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,21 @@ limitations under the License.
1414
package main
1515

1616
/*
17-
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 .
17+
dapr run --app-id job-service --app-port 6400 --dapr-grpc-port 6481 --app-protocol grpc -- go run .
1818
*/
1919

2020
import (
2121
"context"
22-
"encoding/base64"
2322
"encoding/json"
2423
"errors"
2524
"fmt"
2625
"log"
2726
"os"
2827

29-
"github.com/dapr/go-sdk/service/common"
3028
"google.golang.org/protobuf/types/known/anypb"
3129

3230
daprc "github.com/dapr/go-sdk/client"
31+
"github.com/dapr/go-sdk/service/common"
3332
daprs "github.com/dapr/go-sdk/service/grpc"
3433
)
3534

@@ -205,12 +204,9 @@ func handleJob(ctx context.Context, job *common.JobEvent) error {
205204
if err := json.Unmarshal(job.Data, &jobData); err != nil {
206205
return fmt.Errorf("failed to unmarshal job: %v", err)
207206
}
208-
decodedPayload, err := base64.StdEncoding.DecodeString(jobData.Value)
209-
if err != nil {
210-
return fmt.Errorf("failed to decode job payload: %v", err)
211-
}
207+
212208
var jobPayload JobData
213-
if err := json.Unmarshal(decodedPayload, &jobPayload); err != nil {
209+
if err := json.Unmarshal(job.Data, &jobPayload); err != nil {
214210
return fmt.Errorf("failed to unmarshal payload: %v", err)
215211
}
216212

0 commit comments

Comments
 (0)