remove useless dummytask

This commit is contained in:
yusing 2024-11-02 03:14:25 +08:00
parent 67b6e40f85
commit 76454df5e6
3 changed files with 7 additions and 53 deletions

View file

@ -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
}

View file

@ -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() {}

View file

@ -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() {