diff --git a/internal/docker/idlewatcher/waker_http.go b/internal/docker/idlewatcher/waker_http.go index 2634e5fb..9f8085d6 100644 --- a/internal/docker/idlewatcher/waker_http.go +++ b/internal/docker/idlewatcher/waker_http.go @@ -12,7 +12,7 @@ import ( "github.com/yusing/go-proxy/internal/watcher/health" ) -// ServeHTTP implements http.Handler +// ServeHTTP implements http.Handler. func (w *Watcher) ServeHTTP(rw http.ResponseWriter, r *http.Request) { shouldNext := w.wakeFromHTTP(rw, r) if !shouldNext { @@ -81,7 +81,7 @@ func (w *Watcher) wakeFromHTTP(rw http.ResponseWriter, r *http.Request) (shouldN w.WakeTrace().Msg("signal received") err := w.wakeIfStopped() if err != nil { - w.WakeError(err).Send() + w.WakeError(err) http.Error(rw, "Error waking container", http.StatusInternalServerError) return false } diff --git a/internal/task/dummy_task.go b/internal/task/dummy_task.go deleted file mode 100644 index 51eca111..00000000 --- a/internal/task/dummy_task.go +++ /dev/null @@ -1,43 +0,0 @@ -package task - -import "context" - -type dummyTask struct{} - -func DummyTask() (_ Task) { - return -} - -// Context implements Task. -func (d dummyTask) Context() context.Context { - panic("call of dummyTask.Context") -} - -// Finish implements Task. -func (d dummyTask) Finish() {} - -// Name implements Task. -func (d dummyTask) Name() string { - return "Dummy Task" -} - -// OnComplete implements Task. -func (d dummyTask) OnComplete(about string, fn func()) { - panic("call of dummyTask.OnComplete") -} - -// Parent implements Task. -func (d dummyTask) Parent() Task { - panic("call of dummyTask.Parent") -} - -// Subtask implements Task. -func (d dummyTask) Subtask(usageFmt string, args ...any) Task { - panic("call of dummyTask.Subtask") -} - -// Wait implements Task. -func (d dummyTask) Wait() {} - -// WaitSubTasks implements Task. -func (d dummyTask) WaitSubTasks() {} diff --git a/internal/task/task.go b/internal/task/task.go index d848136c..37345150 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -8,7 +8,6 @@ import ( "sync" "time" - "github.com/rs/zerolog" "github.com/yusing/go-proxy/internal/common" E "github.com/yusing/go-proxy/internal/error" "github.com/yusing/go-proxy/internal/logging" @@ -28,8 +27,6 @@ func createGlobalTask() (t *task) { type ( // Task controls objects' lifetime. // - // Task must be initialized, use DummyTask if the task is not yet started. - // // Objects that uses a task should implement the TaskStarter and the TaskFinisher interface. // // When passing a Task object to another function, @@ -167,8 +164,8 @@ func GlobalContextWait(timeout time.Duration) { } } -func (t *task) trace() *zerolog.Event { - return logger.Trace().Str("name", t.name) +func (t *task) trace(msg string) { + logger.Trace().Str("name", t.name).Msg(msg) } func (t *task) Name() string { @@ -244,7 +241,7 @@ func (t *task) OnCancel(about string, fn func()) { <-t.ctx.Done() fn() onCompTask.Finish("done") - t.trace().Msg("onCancel done: " + about) + t.trace("onCancel done: " + about) }() } @@ -284,10 +281,10 @@ func (t *task) newSubTask(ctx context.Context, cancel context.CancelCauseFunc, n parent.subTasksWg.Add(1) parent.subtasks.Add(subtask) if common.IsTrace { - subtask.trace().Msg("started") + subtask.trace("started") go func() { subtask.Wait() - subtask.trace().Msg("finished: " + subtask.FinishCause().Error()) + subtask.trace("finished: " + subtask.FinishCause().Error()) }() } go func() {