-
Notifications
You must be signed in to change notification settings - Fork 24
remove logrus and add new interfaces for worker #155
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
base: main
Are you sure you want to change the base?
Conversation
shaileshpadave
left a comment
There was a problem hiding this 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
| ////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) |
There was a problem hiding this comment.
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 ?
| 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 | ||
| } |
There was a problem hiding this comment.
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
| 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 != "" { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused struct
231d007 to
1a8f74c
Compare
# 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>
f783796 to
9370efa
Compare
| @@ -1,4 +1,4 @@ | |||
| FROM golang:1.17 as build | |||
| FROM golang:1.19 as build | |||
There was a problem hiding this comment.
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.
9370efa to
bb8bab6
Compare
1d15228 to
8c2f12a
Compare
8c2f12a to
13b6dae
Compare
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: