mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 00:45:19 +00:00
Mark calendar webhook as errored so that it doesn't get stuck in pending and keeps logging warnings.
This commit is contained in:
parent
77e74e729b
commit
0bca241680
@ -18,6 +18,7 @@ const (
|
|||||||
CalendarWebhookStatusNone CalendarWebhookStatus = iota
|
CalendarWebhookStatusNone CalendarWebhookStatus = iota
|
||||||
CalendarWebhookStatusPending
|
CalendarWebhookStatusPending
|
||||||
CalendarWebhookStatusSent
|
CalendarWebhookStatusSent
|
||||||
|
CalendarWebhookStatusError
|
||||||
)
|
)
|
||||||
|
|
||||||
type HostCalendarEvent struct {
|
type HostCalendarEvent struct {
|
||||||
|
@ -1133,16 +1133,22 @@ func processCalendarPolicies(
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
if now.Before(calendarEvent.StartTime) {
|
if now.Before(calendarEvent.StartTime) {
|
||||||
level.Warn(logger).Log("msg", "results came too early", "now", now, "start_time", calendarEvent.StartTime)
|
level.Warn(logger).Log("msg", "results came too early", "now", now, "start_time", calendarEvent.StartTime)
|
||||||
|
if err = ds.UpdateHostCalendarWebhookStatus(context.Background(), host.ID, fleet.CalendarWebhookStatusError); err != nil {
|
||||||
|
level.Error(logger).Log("msg", "mark webhook as errored early", "err", err)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO(lucas): Discuss.
|
// TODO(lucas): Discuss.
|
||||||
//
|
//
|
||||||
const allowedTimeBeforeEndTime = 5 * time.Minute // up to 5 minutes before the end_time
|
const allowedTimeRelativeToEndTime = 5 * time.Minute // up to 5 minutes after the end_time to allow for short (0-time) event times
|
||||||
|
|
||||||
if now.After(calendarEvent.EndTime.Add(-allowedTimeBeforeEndTime)) {
|
if now.After(calendarEvent.EndTime.Add(allowedTimeRelativeToEndTime)) {
|
||||||
level.Warn(logger).Log("msg", "results came too late", "now", now, "end_time", calendarEvent.EndTime)
|
level.Warn(logger).Log("msg", "results came too late", "now", now, "end_time", calendarEvent.EndTime)
|
||||||
|
if err = ds.UpdateHostCalendarWebhookStatus(context.Background(), host.ID, fleet.CalendarWebhookStatusError); err != nil {
|
||||||
|
level.Error(logger).Log("msg", "mark webhook as errored late", "err", err)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user