Mark calendar webhook as errored so that it doesn't get stuck in pending and keeps logging warnings.

This commit is contained in:
Victor Lyuboslavsky 2024-04-02 16:03:51 -05:00
parent 77e74e729b
commit 0bca241680
No known key found for this signature in database
2 changed files with 9 additions and 2 deletions

View File

@ -18,6 +18,7 @@ const (
CalendarWebhookStatusNone CalendarWebhookStatus = iota CalendarWebhookStatusNone CalendarWebhookStatus = iota
CalendarWebhookStatusPending CalendarWebhookStatusPending
CalendarWebhookStatusSent CalendarWebhookStatusSent
CalendarWebhookStatusError
) )
type HostCalendarEvent struct { type HostCalendarEvent struct {

View File

@ -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
} }