ashb commented on code in PR #50964:
URL: https://github.com/apache/airflow/pull/50964#discussion_r2104660220


##########
go-sdk/worker/registry.go:
##########
@@ -0,0 +1,98 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package worker
+
+import (
+       "context"
+       "fmt"
+       "log/slog"
+       "reflect"
+       "runtime"
+       "strings"
+       "sync"
+)
+
+type (
+       // task is an interface of an task implementation.
+       Task interface {
+               Execute(ctx context.Context, logger *slog.Logger) error
+       }
+       registry struct {
+               sync.RWMutex
+               taskFuncMap map[string]map[string]Task
+       }
+)
+
+func newRegistry() *registry {
+       return &registry{taskFuncMap: make(map[string]map[string]Task)}
+}
+
+func getFnName(fn reflect.Value) string {
+       fullName := runtime.FuncForPC(fn.Pointer()).Name()
+       parts := strings.Split(fullName, ".")
+       fnName := parts[len(parts)-1]
+       // Go adds `-fm` suffix to a method names
+       return strings.TrimSuffix(fnName, "-fm")
+}
+
+func (r *registry) RegisterTask(dagId string, fn any) {

Review Comment:
   The reflection check is once at startup which seems worth it for the nicer 
UX.  Epseically when it comes to mapped tasks or DAG params etc.
   
   
   I took https://pkg.go.dev/go.temporal.io/[email protected]/worker#ActivityRegistry 
for inspiration



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to