Files
gf/os/gcron/gcron_schedule_fix.go
houseme 94cc233325 fix: disable specific staticcheck rules and update lint config (#4396)
fix: disable specific staticcheck rules and update lint config

- Disabled staticcheck rules SA1029, SA1019, S1000, and related checks
in `.golangci.yml` to filter out unwanted linter errors.
- Updated staticcheck checks list for more precise linting control.
- Clarified configuration for easier maintenance and future updates.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: hailaz <739476267@qq.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-29 10:32:30 +08:00

57 lines
1.8 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"
)
// getAndUpdateLastCheckTimestamp checks fixes and returns the last timestamp that have delay fix in some seconds.
func (s *cronSchedule) getAndUpdateLastCheckTimestamp(ctx context.Context, t time.Time) int64 {
var (
currentTimestamp = t.Unix()
lastCheckTimestamp = s.lastCheckTimestamp.Val()
)
switch lastCheckTimestamp {
// Often happens, timer triggers in the same second, but the millisecond is different.
// Example:
// lastCheckTimestamp: 2024-03-26 19:47:34.000
// currentTimestamp: 2024-03-26 19:47:34.999
case currentTimestamp:
lastCheckTimestamp += 1
// Often happens, no latency.
// Example:
// lastCheckTimestamp: 2024-03-26 19:47:34.000
// currentTimestamp: 2024-03-26 19:47:35.000
case currentTimestamp - 1:
lastCheckTimestamp = currentTimestamp
// Latency in 3 seconds, which can be tolerant.
// Example:
// lastCheckTimestamp: 2024-03-26 19:47:31.000、2024-03-26 19:47:32.000
// currentTimestamp: 2024-03-26 19:47:34.000
case currentTimestamp - 2, currentTimestamp - 3:
lastCheckTimestamp += 1
// Too much latency, it ignores the fix, the cron job might not be triggered.
default:
// Too much delay, let's update the last timestamp to current one.
intlog.Printf(
ctx,
`too much latency, last timestamp "%d", current "%d", latency "%d"`,
lastCheckTimestamp, currentTimestamp, currentTimestamp-lastCheckTimestamp,
)
lastCheckTimestamp = currentTimestamp
}
s.lastCheckTimestamp.Set(lastCheckTimestamp)
return lastCheckTimestamp
}