Add monitoring service and database schema
- Implement monitoring service with heartbeat, lease tasks, resume tasks, and task result handling. - Create monitoring time utilities for business date calculations. - Add unit tests for date window resolution and business day handling. - Define database schema for monitoring-related tables including quotas, daily reports, and task management. - Establish migration scripts for creating and dropping monitoring tables.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const monitoringBusinessTimeZoneName = "Asia/Shanghai"
|
||||
|
||||
var (
|
||||
monitoringBusinessLocationOnce sync.Once
|
||||
monitoringBusinessLocationValue *time.Location
|
||||
)
|
||||
|
||||
func monitoringBusinessLocation() *time.Location {
|
||||
monitoringBusinessLocationOnce.Do(func() {
|
||||
loc, err := time.LoadLocation(monitoringBusinessTimeZoneName)
|
||||
if err != nil {
|
||||
monitoringBusinessLocationValue = time.FixedZone("UTC+8", 8*60*60)
|
||||
return
|
||||
}
|
||||
monitoringBusinessLocationValue = loc
|
||||
})
|
||||
|
||||
return monitoringBusinessLocationValue
|
||||
}
|
||||
|
||||
func monitoringCanonicalBusinessDay(day time.Time) time.Time {
|
||||
return monitoringBusinessDayAt(day, monitoringBusinessLocation())
|
||||
}
|
||||
|
||||
func monitoringBusinessDayAndDateAt(now time.Time) (time.Time, string) {
|
||||
businessDay := monitoringCanonicalBusinessDay(now)
|
||||
return businessDay, businessDay.Format("2006-01-02")
|
||||
}
|
||||
|
||||
func monitoringBusinessDateText(businessDay time.Time) string {
|
||||
return monitoringCanonicalBusinessDay(businessDay).Format("2006-01-02")
|
||||
}
|
||||
Reference in New Issue
Block a user