From 3d98a37374e5b34f15c210c29e67bf4ea4329a00 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 9 Apr 2020 03:06:52 -0700 Subject: [PATCH] instance updates, including: * permdisable instance on 6 failures * restore in proper state on db load --- instance/instance.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/instance/instance.go b/instance/instance.go index 6183b9f..b1585f8 100644 --- a/instance/instance.go +++ b/instance/instance.go @@ -62,6 +62,10 @@ func New(options ...func(i *Instance)) *Instance { opt(i) } + if i.InitialFSMState == "FETCHING" { + i.InitialFSMState = "READY_FOR_TOOTFETCH" + } + i.FSM = fsm.NewFSM( i.InitialFSMState, fsm.Events{ @@ -75,11 +79,13 @@ func New(options ...func(i *Instance)) *Instance { {Name: "EARLY_FETCH_ERROR", Src: []string{"FETCHING_NODEINFO_URL", "PRE_NODEINFO_FETCH", "FETCHING_NODEINFO"}, Dst: "EARLY_ERROR"}, {Name: "TOOT_FETCH_ERROR", Src: []string{"FETCHING"}, Dst: "TOOT_FETCH_ERROR"}, {Name: "TOOTS_FETCHED", Src: []string{"FETCHING"}, Dst: "READY_FOR_TOOTFETCH"}, + {Name: "DISABLEMENT", Src: []string{"WEIRD_NODE", "EARLY_ERROR", "TOOT_FETCH_ERROR"}, Dst: "DISABLED"}, }, fsm.Callbacks{ "enter_state": func(e *fsm.Event) { i.fsmEnterState(e) }, }, ) + return i } @@ -125,8 +131,18 @@ func (i *Instance) Unlock() { func (i *Instance) bumpFetchError() { i.Lock() probablyDead := i.ConsecutiveErrorCount > 3 + shouldDisable := i.ConsecutiveErrorCount > 6 i.Unlock() + if shouldDisable { + // auf wiedersehen, felicia + i.Lock() + i.Disabled = true + i.Unlock() + i.Event("DISABLEMENT") + return + } + if probablyDead { // if three consecutive fetch errors happen, only try once per day: i.setNextFetchAfter(instancePersistentErrorInterval)