mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: more verbose logging with regard to reports
This commit is contained in:
parent
a72af7d57e
commit
8a3e6f0179
@ -73,14 +73,16 @@ func (srv *ReportService) SyncSchedule(u *models.User) bool {
|
|||||||
// unschedule
|
// unschedule
|
||||||
if !u.ReportsWeekly {
|
if !u.ReportsWeekly {
|
||||||
_ = srv.scheduler.RemoveByTag(u.ID)
|
_ = srv.scheduler.RemoveByTag(u.ID)
|
||||||
|
logbuch.Info("disabled scheduled reports for user %s", u.ID)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// schedule
|
// schedule
|
||||||
if j := srv.getJobByTag(u.ID); j == nil && u.ReportsWeekly {
|
if job := srv.getJobByTag(u.ID); job == nil && u.ReportsWeekly {
|
||||||
t, _ := time.ParseInLocation("15:04", srv.config.App.GetWeeklyReportTime(), u.TZ())
|
t, _ := time.ParseInLocation("15:04", srv.config.App.GetWeeklyReportTime(), u.TZ())
|
||||||
t = t.Add(time.Duration(srv.rand.Intn(offsetIntervalMin)*srv.rand.Intn(2)) * time.Minute)
|
t = t.Add(time.Duration(srv.rand.Intn(offsetIntervalMin*60)) * time.Second)
|
||||||
if _, err := srv.scheduler.
|
if job, err := srv.scheduler.
|
||||||
|
SingletonMode().
|
||||||
Every(1).
|
Every(1).
|
||||||
Week().
|
Week().
|
||||||
Weekday(srv.config.App.GetWeeklyReportDay()).
|
Weekday(srv.config.App.GetWeeklyReportDay()).
|
||||||
@ -88,6 +90,8 @@ func (srv *ReportService) SyncSchedule(u *models.User) bool {
|
|||||||
Tag(u.ID).
|
Tag(u.ID).
|
||||||
Do(srv.Run, u, 7*24*time.Hour); err != nil {
|
Do(srv.Run, u, 7*24*time.Hour); err != nil {
|
||||||
config.Log().Error("failed to schedule report job for user '%s' – %v", u.ID, err)
|
config.Log().Error("failed to schedule report job for user '%s' – %v", u.ID, err)
|
||||||
|
} else {
|
||||||
|
logbuch.Info("next report for user %s is scheduled for %v", u.ID, job.NextRun())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +101,7 @@ func (srv *ReportService) SyncSchedule(u *models.User) bool {
|
|||||||
func (srv *ReportService) Run(user *models.User, duration time.Duration) error {
|
func (srv *ReportService) Run(user *models.User, duration time.Duration) error {
|
||||||
if user.Email == "" {
|
if user.Email == "" {
|
||||||
logbuch.Warn("not generating report for '%s' as no e-mail address is set")
|
logbuch.Warn("not generating report for '%s' as no e-mail address is set")
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !srv.SyncSchedule(user) {
|
if !srv.SyncSchedule(user) {
|
||||||
|
Loading…
Reference in New Issue
Block a user