From ff85feb9fe1fb4abd66a80b49137115a3e8301fc Mon Sep 17 00:00:00 2001 From: Sydonian <794346190@qq.com> Date: Tue, 8 Oct 2024 15:28:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=88=E5=B9=B6=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/ioswitch/exec/driver.go | 2 +- pkgs/ioswitch/exec/worker.go | 2 +- sdks/scheduler/modeljob.go | 19 ++++--- utils/time2/test.go | 104 ----------------------------------- 4 files changed, 12 insertions(+), 115 deletions(-) delete mode 100644 utils/time2/test.go diff --git a/pkgs/ioswitch/exec/driver.go b/pkgs/ioswitch/exec/driver.go index 4b51480..927b2f2 100644 --- a/pkgs/ioswitch/exec/driver.go +++ b/pkgs/ioswitch/exec/driver.go @@ -45,7 +45,7 @@ func (e *Driver) Signal(signal *DriverSignalVar) { } func (e *Driver) Wait(ctx context.Context) (map[string]any, error) { - stored, err := e.callback.WaitValue(ctx) + stored, err := e.callback.Wait(ctx) if err != nil { return nil, err } diff --git a/pkgs/ioswitch/exec/worker.go b/pkgs/ioswitch/exec/worker.go index b9bf4f8..8f6e2c7 100644 --- a/pkgs/ioswitch/exec/worker.go +++ b/pkgs/ioswitch/exec/worker.go @@ -75,7 +75,7 @@ func (s *Worker) FindByIDContexted(ctx context.Context, id PlanID) *Executor { s.lock.Unlock() - sw, _ = cb.WaitValue(ctx) + sw, _ = cb.Wait(ctx) s.lock.Lock() defer s.lock.Unlock() diff --git a/sdks/scheduler/modeljob.go b/sdks/scheduler/modeljob.go index d896760..cd88bd7 100644 --- a/sdks/scheduler/modeljob.go +++ b/sdks/scheduler/modeljob.go @@ -2,12 +2,13 @@ package schsdk import ( "fmt" + "net/url" + "strings" + "gitlink.org.cn/cloudream/common/consts/errorcode" "gitlink.org.cn/cloudream/common/pkgs/mq" - myhttp "gitlink.org.cn/cloudream/common/utils/http" + "gitlink.org.cn/cloudream/common/utils/http2" "gitlink.org.cn/cloudream/common/utils/serder" - "net/url" - "strings" ) // 这个结构体无任何字段,但实现了Noop,每种MessageBody都要内嵌这个结构体 @@ -112,7 +113,7 @@ func (c *Client) QueryRunningModels(req QueryRunningModelsReq) (*RunningModelRes return nil, err } - resp, err := myhttp.GetJSON(url, myhttp.RequestParam{ + resp, err := http2.GetJSON(url, http2.RequestParam{ Body: req, }) if err != nil { @@ -120,7 +121,7 @@ func (c *Client) QueryRunningModels(req QueryRunningModelsReq) (*RunningModelRes } contType := resp.Header.Get("Content-Type") - if strings.Contains(contType, myhttp.ContentTypeJSON) { + if strings.Contains(contType, http2.ContentTypeJSON) { var codeResp response[RunningModelResp] if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil { return nil, fmt.Errorf("parsing response: %w", err) @@ -142,7 +143,7 @@ func (c *Client) QueryAllModels(req QueryRunningModelsReq) (*AllModelResp, error return nil, err } - resp, err := myhttp.GetJSON(url, myhttp.RequestParam{ + resp, err := http2.GetJSON(url, http2.RequestParam{ Body: req, }) if err != nil { @@ -150,7 +151,7 @@ func (c *Client) QueryAllModels(req QueryRunningModelsReq) (*AllModelResp, error } contType := resp.Header.Get("Content-Type") - if strings.Contains(contType, myhttp.ContentTypeJSON) { + if strings.Contains(contType, http2.ContentTypeJSON) { var codeResp response[AllModelResp] if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil { return nil, fmt.Errorf("parsing response: %w", err) @@ -172,7 +173,7 @@ func (c *Client) ECSNodeRunningInfo(req ECSNodeRunningInfoReq) (*ECSNodeRunningI return nil, err } - resp, err := myhttp.GetJSON(url, myhttp.RequestParam{ + resp, err := http2.GetJSON(url, http2.RequestParam{ Body: req, }) if err != nil { @@ -180,7 +181,7 @@ func (c *Client) ECSNodeRunningInfo(req ECSNodeRunningInfoReq) (*ECSNodeRunningI } contType := resp.Header.Get("Content-Type") - if strings.Contains(contType, myhttp.ContentTypeJSON) { + if strings.Contains(contType, http2.ContentTypeJSON) { var codeResp response[ECSNodeRunningInfoResp] if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil { return nil, fmt.Errorf("parsing response: %w", err) diff --git a/utils/time2/test.go b/utils/time2/test.go deleted file mode 100644 index 07be5b2..0000000 --- a/utils/time2/test.go +++ /dev/null @@ -1,104 +0,0 @@ -package time2 - -import ( - "fmt" - "path" - "runtime" - "strings" - "time" -) - -type Measurement struct { - startTime time.Time - lastPointTime time.Time - printer func(string) - on bool - title string -} - -func NewMeasurement(printer func(string)) Measurement { - return Measurement{ - printer: printer, - } -} - -func (m *Measurement) Begin(on bool, title ...string) { - if m == nil { - return - } - - m.on = on - m.title = strings.Join(title, ".") - - if on { - m.startTime = time.Now() - m.lastPointTime = m.startTime - - _, file, line, ok := runtime.Caller(1) - - titlePart := "" - if m.title != "" { - titlePart = fmt.Sprintf(":%s", m.title) - } - - if ok { - m.printer(fmt.Sprintf("[begin%v]%v:%v", titlePart, path.Base(file), line)) - } else { - m.printer(fmt.Sprintf("[begin%v]unknown point", titlePart)) - } - } -} - -func (m *Measurement) Point(head ...string) { - if m == nil { - return - } - - if m.on { - m.printer(m.makePointString(strings.Join(head, "."))) - } -} - -func (m *Measurement) makePointString(head string) string { - last := m.lastPointTime - now := time.Now() - m.lastPointTime = now - - _, file, line, ok := runtime.Caller(2) - - prefixCont := "" - - if m.title != "" { - prefixCont = m.title - } - - if head != "" { - if prefixCont == "" { - prefixCont = head - } else { - prefixCont = fmt.Sprintf("%s.%s", prefixCont, head) - } - } - - prefixPart := "" - if prefixCont != "" { - prefixPart = fmt.Sprintf("[%s]", prefixCont) - } - - if ok { - return fmt.Sprintf("%v%v:%v@%v(%v)", prefixPart, path.Base(file), line, now.Sub(last), now.Sub(m.startTime)) - } - - return fmt.Sprintf("%vunknown point@%v(%v)", prefixPart, now.Sub(last), now.Sub(m.startTime)) -} - -func (m *Measurement) End(head ...string) { - if m == nil { - return - } - - if m.on { - m.printer(fmt.Sprintf("[end]%v\n", m.makePointString(strings.Join(head, ".")))) - } -} -