80th time's the charm.
This commit is contained in:
parent
7c5d55e0b9
commit
0cffbbb3cd
|
@ -75,7 +75,10 @@ func DBTimeout() time.Duration {
|
|||
return -1
|
||||
}
|
||||
|
||||
var pint int64
|
||||
|
||||
func StartTick() (abort bool) {
|
||||
opint := pint
|
||||
db := qgen.Builder.GetConn()
|
||||
isDBDown := atomic.LoadInt32(&IsDBDown)
|
||||
if e := db.Ping(); e != nil {
|
||||
|
@ -92,7 +95,7 @@ func StartTick() (abort bool) {
|
|||
}
|
||||
db.SetConnMaxLifetime(DBTimeout())
|
||||
atomic.StoreInt32(&IsDBDown, 0)
|
||||
return false
|
||||
return opint != pint
|
||||
}
|
||||
|
||||
// TODO: Move these into DailyTick() methods?
|
||||
|
@ -234,9 +237,10 @@ type TickWatch struct {
|
|||
Tasks int64
|
||||
EndHook int64
|
||||
|
||||
Ticker *time.Ticker
|
||||
Deadline *time.Ticker
|
||||
EndChan chan bool
|
||||
Ticker *time.Ticker
|
||||
Deadline *time.Ticker
|
||||
EndChan chan bool
|
||||
OutEndChan chan bool
|
||||
}
|
||||
|
||||
func NewTickWatch() *TickWatch {
|
||||
|
@ -297,6 +301,7 @@ func (w *TickWatch) DumpElapsed() {
|
|||
func (w *TickWatch) Run() {
|
||||
w.EndChan = make(chan bool)
|
||||
// Use a goroutine to circumvent ticks which never end
|
||||
// TODO: Reuse goroutines across multiple *TickWatch?
|
||||
go func() {
|
||||
defer w.Ticker.Stop()
|
||||
defer close(w.EndChan)
|
||||
|
@ -333,6 +338,10 @@ func (w *TickWatch) Run() {
|
|||
Log("tick " + w.Name + " completed in " + dur.String())
|
||||
w.DumpElapsed()
|
||||
}
|
||||
if w.OutEndChan != nil {
|
||||
w.OutEndChan <- true
|
||||
close(w.OutEndChan)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
15
tickloop.go
15
tickloop.go
|
@ -59,13 +59,25 @@ func tickLoop(thumbChan chan bool) error {
|
|||
return e
|
||||
}
|
||||
|
||||
startTick := func(ch chan bool) (ret bool) {
|
||||
if c.Dev.HourDBTimeout {
|
||||
go func() {
|
||||
defer c.EatPanics()
|
||||
ch <- c.StartTick()
|
||||
}()
|
||||
return <-ch
|
||||
}
|
||||
return c.StartTick()
|
||||
}
|
||||
tick := func(name string, tasks c.TaskSet, secs int) error {
|
||||
tw := c.NewTickWatch()
|
||||
tw.Name = name
|
||||
tw.Set(&tw.Start, uutils.Nanotime())
|
||||
tw.Run()
|
||||
defer tw.Stop()
|
||||
if c.StartTick() {
|
||||
ch := make(chan bool)
|
||||
tw.OutEndChan = ch
|
||||
if startTick(ch) {
|
||||
return nil
|
||||
}
|
||||
tw.Set(&tw.DBCheck, uutils.Nanotime())
|
||||
|
@ -83,6 +95,7 @@ func tickLoop(thumbChan chan bool) error {
|
|||
return e
|
||||
}
|
||||
tw.Set(&tw.EndHook, uutils.Nanotime())
|
||||
//close(tw.OutEndChan)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue