yuluo-yx commented on code in PR #11:
URL: 
https://github.com/apache/hertzbeat-collector-go/pull/11#discussion_r2330415469


##########
internal/collector/common/dispatcher/common_dispatcher.go:
##########
@@ -0,0 +1,244 @@
+/*
+ * 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 dispatcher
+
+import (
+       "context"
+       "fmt"
+       "sync"
+       "time"
+
+       jobtypes 
"hertzbeat.apache.org/hertzbeat-collector-go/internal/collector/common/types/job"
+       "hertzbeat.apache.org/hertzbeat-collector-go/internal/util/logger"
+)
+
+// CommonDispatcherImpl is responsible for breaking down jobs into individual 
metrics collection tasks
+// It manages collection timeouts, handles results, and decides on next round 
scheduling
+type CommonDispatcherImpl struct {
+       logger           logger.Logger
+       metricsCollector MetricsCollector
+       resultHandler    ResultHandler
+       ctx              context.Context
+       cancel           context.CancelFunc
+       mu               sync.RWMutex
+}
+
+// MetricsCollector interface for metrics collection
+type MetricsCollector interface {
+       CollectMetrics(metrics *jobtypes.Metrics, job *jobtypes.Job, timeout 
*jobtypes.Timeout) chan *jobtypes.CollectRepMetricsData
+}
+
+// ResultHandler interface for handling collection results
+type ResultHandler interface {
+       HandleCollectData(data *jobtypes.CollectRepMetricsData, job 
*jobtypes.Job) error
+}
+
+// NewCommonDispatcher creates a new common dispatcher
+func NewCommonDispatcher(logger logger.Logger, metricsCollector 
MetricsCollector, resultHandler ResultHandler) *CommonDispatcherImpl {

Review Comment:
   这里应该创建一个 ctx 吗?
   
   从 go 的编程风格来说,ctx 应该永远被用作函数的第一个参数实现,而不是放到结构体里面去,这不符合 go 的编程规范(约定俗成



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to