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

Go/SDK Jobs Example - JobEvent Data fails to parse #1095

Closed
tazarov opened this issue Oct 6, 2024 · 1 comment
Closed

Go/SDK Jobs Example - JobEvent Data fails to parse #1095

tazarov opened this issue Oct 6, 2024 · 1 comment

Comments

@tazarov
Copy link

tazarov commented Oct 6, 2024

Expected Behavior

'== APP - job-service == Starting droid: R2-D2'
'== APP - job-service == Executing maintenance job: Oil Change'
'== APP - job-service == Starting droid: C-3PO'
'== APP - job-service == Executing maintenance job: Memory Wipe'

Actual Behavior

== APP - job-service == Job scheduled:  R2-D2
== APP - job-service == Job scheduled:  C-3PO
== APP - job-service == 2024/10/06 15:43:19 job:{name:"C-3PO" due_time:"15s" data:{value:"{\"droid\":\"C-3PO\",\"Task\":\"Memory Wipe\"}"}}
== APP - job-scheduler == Get job response:  {"droid":"C-3PO","Task":"Memory Wipe"}
== APP - job-service == Job scheduled:  BB-8
== APP - job-service == 2024/10/06 15:43:19 job:{name:"BB-8" due_time:"30s" data:{value:"{\"droid\":\"BB-8\",\"Task\":\"Internal Gyroscope Check\"}"}}
== APP - job-scheduler == Get job response:  {"droid":"BB-8","Task":"Internal Gyroscope Check"}
== APP - job-scheduler == Job deleted:  BB-8
Exited App successfully
ERRO[0021] unexpected status code returned from app while processing triggered job R2-D2. status code returned: 2  app_id=job-service instance=Nordrassil.local scope=dapr.runtime.scheduler type=log ver=1.14.4
ERRO[0031] unexpected status code returned from app while processing triggered job C-3PO. status code returned: 2  app_id=job-service instance=Nordrassil.local scope=dapr.runtime.scheduler type=log ver=1.14.4

Steps to Reproduce the Problem

Run the existing example with:

[quickstarts] dapr build-info
CLI:
        Version: 1.14.1
        Git Commit: 
        Git Version: 
Runtime:
        Version: 1.14.4
        Git Commit: 583960dc90120616124b60ad2b7820fc0b3edf44
        Git Version: 583960d

Analysis

It would appear that API has changed and now the common.JobEvent contains the actual Job payload as opposed to expected common.Job (job spec).

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

// Handler that handles job events
func handleJob(ctx context.Context, job *common.JobEvent) error {
	var jobPayload JobData
	if err := json.Unmarshal(job.Data, &jobPayload); err != nil {
		return fmt.Errorf("failed to unmarshal payload: %v", err)
	}

	fmt.Println("Starting droid:", jobPayload.Droid)
	fmt.Println("Executing maintenance job:", jobPayload.Task)

	return nil
}

After the fix we see the expected output:

== APP - job-service == Job scheduled:  R2-D2
== APP - job-service == Job scheduled:  C-3PO
== APP - job-service == 2024/10/06 15:51:38 job:{name:"C-3PO"  due_time:"15s"  data:{value:"{\"droid\":\"C-3PO\",\"Task\":\"Memory Wipe\"}"}}
== APP - job-scheduler == Get job response:  {"droid":"C-3PO","Task":"Memory Wipe"}
== APP - job-service == Job scheduled:  BB-8
== APP - job-service == 2024/10/06 15:51:38 job:{name:"BB-8"  due_time:"30s"  data:{value:"{\"droid\":\"BB-8\",\"Task\":\"Internal Gyroscope Check\"}"}}
== APP - job-scheduler == Get job response:  {"droid":"BB-8","Task":"Internal Gyroscope Check"}
== APP - job-scheduler == Job deleted:  BB-8
Exited App successfully
== APP - job-service == Starting droid: R2-D2
== APP - job-service == Executing maintenance job: Oil Change
== APP - job-service == Starting droid: C-3PO
== APP - job-service == Executing maintenance job: Memory Wipe
@tazarov tazarov changed the title Go/SDK Jobs Example is not working Go/SDK Jobs Example - JobEvent Data fails to parse Oct 6, 2024
@tazarov
Copy link
Author

tazarov commented Oct 8, 2024

Closing, fixed by @cicoyle in #1097

@tazarov tazarov closed this as completed Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant