Fix time comparison bug
This commit is contained in:
parent
be991e9665
commit
87c00030fd
@ -89,11 +89,6 @@ func (a *Action) exec(match string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func quasiBefore(then, now time.Time) bool {
|
|
||||||
// We won't complain if it's executed less than 1sec earlier
|
|
||||||
return then.Unix() <= now.Add(1*time.Second).Unix()
|
|
||||||
}
|
|
||||||
|
|
||||||
func ActionsManager() {
|
func ActionsManager() {
|
||||||
actions := make(ActionsMap)
|
actions := make(ActionsMap)
|
||||||
pendingActionsC := make(chan PAT)
|
pendingActionsC := make(chan PAT)
|
||||||
@ -112,7 +107,7 @@ func ActionsManager() {
|
|||||||
then = pat.t
|
then = pat.t
|
||||||
now = time.Now()
|
now = time.Now()
|
||||||
// check
|
// check
|
||||||
if quasiBefore(then, now) {
|
if then.Compare(now) <= 0 {
|
||||||
wgActions.Add(1)
|
wgActions.Add(1)
|
||||||
go action.exec(match)
|
go action.exec(match)
|
||||||
} else {
|
} else {
|
||||||
@ -122,27 +117,17 @@ func ActionsManager() {
|
|||||||
}
|
}
|
||||||
// append() to nil is valid go
|
// append() to nil is valid go
|
||||||
actions[action][match] = append(actions[action][match], then)
|
actions[action][match] = append(actions[action][match], then)
|
||||||
go func(pat PAT) {
|
go func(pat PAT, now time.Time) {
|
||||||
log.Printf("DEBUG then: %v, now: %v, then.Sub(now): %v", then.String(), now.String(), then.Sub(now).String())
|
time.Sleep(pat.t.Sub(now))
|
||||||
time.Sleep(then.Sub(now))
|
|
||||||
pendingActionsC <- pat
|
pendingActionsC <- pat
|
||||||
}(pat)
|
}(pat, now)
|
||||||
}
|
}
|
||||||
// FIXME convert to pendingActionsC to chan PA
|
|
||||||
// and forget about time checking
|
|
||||||
case pat = <-pendingActionsC:
|
case pat = <-pendingActionsC:
|
||||||
match = pat.p
|
match = pat.p
|
||||||
action = pat.a
|
action = pat.a
|
||||||
then = pat.t
|
actions[action][match] = actions[action][match][1:]
|
||||||
now = time.Now()
|
wgActions.Add(1)
|
||||||
if quasiBefore(then, now) {
|
go action.exec(match)
|
||||||
actions[action][match] = actions[action][match][1:]
|
|
||||||
wgActions.Add(1)
|
|
||||||
go action.exec(match)
|
|
||||||
} else {
|
|
||||||
// This should not happen
|
|
||||||
log.Fatalf("ERROR pendingActionsC then: %v << now %v\n", pat.t.String(), now)
|
|
||||||
}
|
|
||||||
case _, _ = <-stopActions:
|
case _, _ = <-stopActions:
|
||||||
for action := range actions {
|
for action := range actions {
|
||||||
if action.OnExit {
|
if action.OnExit {
|
||||||
|
Loading…
Reference in New Issue
Block a user