mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-06 21:24:10 +00:00
- Update go.mod module path from mhsanaei/3x-ui/v3 to saeederamy/3x-ui/v3 - Update all 73 Go files' import paths accordingly - Fix README.fa_IR.md install command to point to fork's main branch The fork was referencing the original repo's module path in go.mod and all Go source imports, making it dependent on MHSanaei's namespace at build time. https://claude.ai/code/session_01M6d5atbWjuLTj6UwRHoK5m
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package job
|
|
|
|
import (
|
|
"github.com/saeederamy/3x-ui/v3/logger"
|
|
"github.com/saeederamy/3x-ui/v3/web/service"
|
|
)
|
|
|
|
// Period represents the time period for traffic resets.
|
|
type Period string
|
|
|
|
// PeriodicTrafficResetJob resets traffic statistics for inbounds based on their configured reset period.
|
|
type PeriodicTrafficResetJob struct {
|
|
inboundService service.InboundService
|
|
period Period
|
|
}
|
|
|
|
// NewPeriodicTrafficResetJob creates a new periodic traffic reset job for the specified period.
|
|
func NewPeriodicTrafficResetJob(period Period) *PeriodicTrafficResetJob {
|
|
return &PeriodicTrafficResetJob{
|
|
period: period,
|
|
}
|
|
}
|
|
|
|
// Run resets traffic statistics for all inbounds that match the configured reset period.
|
|
func (j *PeriodicTrafficResetJob) Run() {
|
|
inbounds, err := j.inboundService.GetInboundsByTrafficReset(string(j.period))
|
|
if err != nil {
|
|
logger.Warning("Failed to get inbounds for traffic reset:", err)
|
|
return
|
|
}
|
|
|
|
if len(inbounds) == 0 {
|
|
return
|
|
}
|
|
logger.Infof("Running periodic traffic reset job for period: %s (%d matching inbounds)", j.period, len(inbounds))
|
|
|
|
resetCount := 0
|
|
|
|
for _, inbound := range inbounds {
|
|
resetInboundErr := j.inboundService.ResetInboundTraffic(inbound.Id)
|
|
if resetInboundErr != nil {
|
|
logger.Warning("Failed to reset traffic for inbound", inbound.Id, ":", resetInboundErr)
|
|
}
|
|
|
|
resetClientErr := j.inboundService.ResetAllClientTraffics(inbound.Id)
|
|
if resetClientErr != nil {
|
|
logger.Warning("Failed to reset traffic for all users of inbound", inbound.Id, ":", resetClientErr)
|
|
}
|
|
|
|
if resetInboundErr == nil && resetClientErr == nil {
|
|
resetCount++
|
|
}
|
|
}
|
|
|
|
if resetCount > 0 {
|
|
logger.Infof("Periodic traffic reset completed: %d inbounds reset", resetCount)
|
|
}
|
|
}
|