mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-07 03:52:34 +02:00
fix(idlewatcher): wake time outs before actual timeout
This commit is contained in:
parent
9087c4f195
commit
e737737415
2 changed files with 5 additions and 8 deletions
|
@ -90,16 +90,14 @@ func (w *Watcher) wakeFromHTTP(rw http.ResponseWriter, r *http.Request) (shouldN
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeoutCause(r.Context(), w.cfg.WakeTimeout, errors.New("wake timeout"))
|
ctx := r.Context()
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
if w.cancelled(ctx) {
|
if w.cancelled(ctx) {
|
||||||
gphttp.ServerError(rw, r, context.Cause(ctx), http.StatusServiceUnavailable)
|
gphttp.ServerError(rw, r, context.Cause(ctx), http.StatusServiceUnavailable)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
w.l.Trace().Msg("signal received")
|
w.l.Trace().Msg("signal received")
|
||||||
err := w.wakeIfStopped()
|
err := w.Wake(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gphttp.ServerError(rw, r, err)
|
gphttp.ServerError(rw, r, err)
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -186,18 +186,17 @@ func (w *Watcher) Key() string {
|
||||||
return w.cfg.Key()
|
return w.cfg.Key()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Watcher) Wake() error {
|
func (w *Watcher) Wake(ctx context.Context) error {
|
||||||
return w.wakeIfStopped()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Watcher) wakeIfStopped() error {
|
func (w *Watcher) wakeIfStopped(ctx context.Context) error {
|
||||||
state := w.state.Load()
|
state := w.state.Load()
|
||||||
if state.status == idlewatcher.ContainerStatusRunning {
|
if state.status == idlewatcher.ContainerStatusRunning {
|
||||||
w.l.Debug().Msg("container is already running")
|
w.l.Debug().Msg("container is already running")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(w.task.Context(), w.cfg.WakeTimeout)
|
ctx, cancel := context.WithTimeout(ctx, w.cfg.WakeTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
switch state.status {
|
switch state.status {
|
||||||
case idlewatcher.ContainerStatusStopped:
|
case idlewatcher.ContainerStatusStopped:
|
||||||
|
|
Loading…
Add table
Reference in a new issue