@@ -296,9 +296,7 @@ func processFailingHostExistingCalendarEvent(
296
296
updated := false
297
297
now := time .Now ()
298
298
299
- // Check the user calendar every 30 minutes (and not every time)
300
- // to reduce load on both Fleet and the calendar service.
301
- if time .Since (calendarEvent .UpdatedAt ) > 30 * time .Minute {
299
+ if shouldReloadCalendarEvent (now , calendarEvent , hostCalendarEvent ) {
302
300
var err error
303
301
updatedEvent , _ , err = calendar .GetAndUpdateEvent (calendarEvent , func (conflict bool ) string {
304
302
return generateCalendarEventBody (orgName , host .HostDisplayName , conflict )
@@ -365,6 +363,24 @@ func processFailingHostExistingCalendarEvent(
365
363
return nil
366
364
}
367
365
366
+ func shouldReloadCalendarEvent (now time.Time , calendarEvent * fleet.CalendarEvent , hostCalendarEvent * fleet.HostCalendarEvent ) bool {
367
+ // Check the user calendar every 30 minutes (and not every cron run)
368
+ // to reduce load on both Fleet and the calendar service.
369
+ if time .Since (calendarEvent .UpdatedAt ) > 30 * time .Minute {
370
+ return true
371
+ }
372
+ // If the event is supposed to be happening now, we want to check if the user moved/deleted the
373
+ // event on the last minute.
374
+ if eventHappeningNow (now , calendarEvent ) && hostCalendarEvent .WebhookStatus == fleet .CalendarWebhookStatusNone {
375
+ return true
376
+ }
377
+ return false
378
+ }
379
+
380
+ func eventHappeningNow (now time.Time , calendarEvent * fleet.CalendarEvent ) bool {
381
+ return ! now .Before (calendarEvent .StartTime ) && now .Before (calendarEvent .EndTime )
382
+ }
383
+
368
384
func sameDate (t1 time.Time , t2 time.Time ) bool {
369
385
y1 , m1 , d1 := t1 .Date ()
370
386
y2 , m2 , d2 := t2 .Date ()
0 commit comments