Skip to content

Conversation

@v1r3n
Copy link
Collaborator

@v1r3n v1r3n commented Oct 20, 2024

Test Fix in kitchensink:
When we return a TaskResult object from a worker function, the framework tries to extract the output from it, but this can cause serialization issues. The framework expects workers to return raw output data, which it then wraps in a TaskResult automatically.

Added tests:

  • TestLegacyWorkerIntegration - Tests old StartWorker() pattern with model.ExecuteTaskFunction
  • TestTypedWorkerIntegration - Tests new NewWorkerWithCtx() with custom struct types (TestData)
  • TestSimpleTypedWorkerIntegration - Tests new typed worker with generic map[string]interface{} input/output
  • TestMultiTaskWorkflowIntegration - Tests sequential workflow with mixed worker types (legacy + typed + simple)
  • TestParallelExecutionIntegration - Tests fork-join parallel execution with typed workers
  • TestBatchProcessing - Tests high batch size processing with multiple sequential tasks

Copy link
Contributor

@shaileshpadave shaileshpadave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added few suggestions

sdk/main/main.go Outdated
Comment on lines 124 to 153
////worker := worker.NewWorker("hello", ProcessBody)
//
////taskClient := client.NewTaskClient(apiClient)
////workerFn, _ := worker.GetWorker(ProcessBody)
////_ = taskRunner.StartWorker2("hello", workerFn, 1, 1)
//
//opts := &client.TaskResourceApiBatchPollOpts{}
//tasks, _, err := taskClient.BatchPollTask(context.Background(), "hello", opts)
////task := model.PolledTask{
//// TaskType: "abcd",
//// InputData: "{}",
//// OutputData: "{}",
////}
//if err != nil {
// fmt.Println("Got error ", err.Error())
//}
//fmt.Println("Got", len(tasks))

//for i := range tasks {
// fmt.Println("Task.Id", tasks[i].TaskId)
// res, err := te.Execute(&tasks[i])
// if err != nil {
// fmt.Println("Error executing process body ", err.Error())
// } else {
// fmt.Println("Response of process body", res)
// }
//}

//data, _ := json.Marshal(task.InputData)
//jsons := string(data)
//fmt.Println(jsons)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this commented code ?

Comment on lines +60 to +71
func (task *PolledTask) ToValue(newValue any) (interface{}, error) {

bytes, err := task.InputData.MarshalJSON()
if err != nil {
return nil, err
}
err = json.Unmarshal(bytes, newValue)
if err != nil {
return nil, err
}
return newValue, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directly unmarshalling task.InputData into newValue

Suggested change
func (task *PolledTask) ToValue(newValue any) (interface{}, error) {
bytes, err := task.InputData.MarshalJSON()
if err != nil {
return nil, err
}
err = json.Unmarshal(bytes, newValue)
if err != nil {
return nil, err
}
return newValue, nil
}
func (task *PolledTask) ToValue(newValue interface{}) (interface{}, error) {
err := json.Unmarshal(task.InputData, newValue)
if err != nil {
return nil, err
}
return newValue, nil
}

sdk/main/main.go Outdated
func authSettings() *settings.AuthenticationSettings {
key := "api_key_user_03"
secret := "api_key_user_03"
if key != "" && secret != "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we be replacing the key and secret somewhere, else can ignore the checks

sdk/main/main.go Outdated
func ProcessBody(body *Data) (*Data, error) {
if body == nil {
fmt.Println("Body is nil")
return nil, nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: error standardization maybe in some common file

"encoding/xml"
"errors"
"fmt"
"github.com/conductor-sdk/conductor-go/sdk/log"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: linters could be introduced.

sdk/main/main.go Outdated
}

func ProcessBody2(task *model.Task) (interface{}, error) {
fmt.Println("executing", task.TaskId)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: usage of logs instead of print with the correct log level to help in debugging later

sdk/main/main.go Outdated
"github.com/conductor-sdk/conductor-go/sdk/worker"
)

type Restaurant struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused struct

@shaileshpadave shaileshpadave force-pushed the logger_and_worker branch 12 times, most recently from 231d007 to 1a8f74c Compare May 3, 2025 18:39
v1r3n and others added 8 commits May 23, 2025 16:59
# Conflicts:
#	go.mod
#	go.sum
#	sdk/client/api_task_resource.go
#	sdk/log/logger.go
#	sdk/worker/task_runner.go
Co-authored-by: Shailesh Padave <shaileshpadave49@gmail.com>
Co-authored-by: Shailesh Padave <shaileshpadave49@gmail.com>
Co-authored-by: Shailesh Padave <shaileshpadave49@gmail.com>
@@ -1,4 +1,4 @@
FROM golang:1.17 as build
FROM golang:1.19 as build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not upgrade to. 19 as Miguel mentioned in last pr that it might break few things, so i would say lets take this into another separate PR.

Shailesh Jagannath Padave added 2 commits May 23, 2025 18:39
@shaileshpadave shaileshpadave requested a review from a team May 23, 2025 18:22
@shaileshpadave shaileshpadave marked this pull request as ready for review May 23, 2025 18:23
@ArtemIstomin-sm
Copy link
Contributor

@v1r3n several features have already been added to the sdk in other PRs
#204
#206
If there are no objections, consider closing this PR.

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 this pull request may close these issues.

5 participants