mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 09:48:49 +02:00
remove useless dummytask
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/yusing/go-proxy/internal/watcher/health"
|
"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) {
|
func (w *Watcher) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||||
shouldNext := w.wakeFromHTTP(rw, r)
|
shouldNext := w.wakeFromHTTP(rw, r)
|
||||||
if !shouldNext {
|
if !shouldNext {
|
||||||
@@ -81,7 +81,7 @@ func (w *Watcher) wakeFromHTTP(rw http.ResponseWriter, r *http.Request) (shouldN
|
|||||||
w.WakeTrace().Msg("signal received")
|
w.WakeTrace().Msg("signal received")
|
||||||
err := w.wakeIfStopped()
|
err := w.wakeIfStopped()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WakeError(err).Send()
|
w.WakeError(err)
|
||||||
http.Error(rw, "Error waking container", http.StatusInternalServerError)
|
http.Error(rw, "Error waking container", http.StatusInternalServerError)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {}
|
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
E "github.com/yusing/go-proxy/internal/error"
|
E "github.com/yusing/go-proxy/internal/error"
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
"github.com/yusing/go-proxy/internal/logging"
|
||||||
@@ -28,8 +27,6 @@ func createGlobalTask() (t *task) {
|
|||||||
type (
|
type (
|
||||||
// Task controls objects' lifetime.
|
// 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.
|
// Objects that uses a task should implement the TaskStarter and the TaskFinisher interface.
|
||||||
//
|
//
|
||||||
// When passing a Task object to another function,
|
// When passing a Task object to another function,
|
||||||
@@ -167,8 +164,8 @@ func GlobalContextWait(timeout time.Duration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *task) trace() *zerolog.Event {
|
func (t *task) trace(msg string) {
|
||||||
return logger.Trace().Str("name", t.name)
|
logger.Trace().Str("name", t.name).Msg(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *task) Name() string {
|
func (t *task) Name() string {
|
||||||
@@ -244,7 +241,7 @@ func (t *task) OnCancel(about string, fn func()) {
|
|||||||
<-t.ctx.Done()
|
<-t.ctx.Done()
|
||||||
fn()
|
fn()
|
||||||
onCompTask.Finish("done")
|
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.subTasksWg.Add(1)
|
||||||
parent.subtasks.Add(subtask)
|
parent.subtasks.Add(subtask)
|
||||||
if common.IsTrace {
|
if common.IsTrace {
|
||||||
subtask.trace().Msg("started")
|
subtask.trace("started")
|
||||||
go func() {
|
go func() {
|
||||||
subtask.Wait()
|
subtask.Wait()
|
||||||
subtask.trace().Msg("finished: " + subtask.FinishCause().Error())
|
subtask.trace("finished: " + subtask.FinishCause().Error())
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user