mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
ae4f14c2e2
* improve logging feature, add LevelPrint configuration for glog.Logger; add package internal/instance * improve command build * add default logger for panic message printing if no logger set * up * fix scheduler when timer triggers in less than one second for package gcron * up
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gcron
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/gogf/gf/v2/internal/intlog"
|
|
)
|
|
|
|
// getAndUpdateLastTimestamp checks fixes and returns the last timestamp that have delay fix in some seconds.
|
|
func (s *cronSchedule) getAndUpdateLastTimestamp(ctx context.Context, t time.Time) int64 {
|
|
var (
|
|
currentTimestamp = t.Unix()
|
|
lastTimestamp = s.lastTimestamp.Val()
|
|
)
|
|
switch {
|
|
case
|
|
lastTimestamp == currentTimestamp:
|
|
lastTimestamp += 1
|
|
|
|
case
|
|
lastTimestamp == currentTimestamp-1:
|
|
lastTimestamp = currentTimestamp
|
|
|
|
case
|
|
lastTimestamp == currentTimestamp-2,
|
|
lastTimestamp == currentTimestamp-3:
|
|
lastTimestamp += 1
|
|
|
|
default:
|
|
// Too much delay, let's update the last timestamp to current one.
|
|
intlog.Printf(
|
|
ctx,
|
|
`too much delay, last timestamp "%d", current "%d"`,
|
|
lastTimestamp, currentTimestamp,
|
|
)
|
|
lastTimestamp = currentTimestamp
|
|
}
|
|
s.lastTimestamp.Set(lastTimestamp)
|
|
return lastTimestamp
|
|
}
|