mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 01:18:42 +00:00
Calendar update event if meeting occurring now (#17815)
#17441 --------- Co-authored-by: Victor Lyuboslavsky <victor.lyuboslavsky@gmail.com>
This commit is contained in:
parent
2e56563280
commit
9090d8541f
1 changed files with 19 additions and 3 deletions
|
|
@ -296,9 +296,7 @@ func processFailingHostExistingCalendarEvent(
|
|||
updated := false
|
||||
now := time.Now()
|
||||
|
||||
// Check the user calendar every 30 minutes (and not every time)
|
||||
// to reduce load on both Fleet and the calendar service.
|
||||
if time.Since(calendarEvent.UpdatedAt) > 30*time.Minute {
|
||||
if shouldReloadCalendarEvent(now, calendarEvent, hostCalendarEvent) {
|
||||
var err error
|
||||
updatedEvent, _, err = calendar.GetAndUpdateEvent(calendarEvent, func(conflict bool) string {
|
||||
return generateCalendarEventBody(orgName, host.HostDisplayName, conflict)
|
||||
|
|
@ -365,6 +363,24 @@ func processFailingHostExistingCalendarEvent(
|
|||
return nil
|
||||
}
|
||||
|
||||
func shouldReloadCalendarEvent(now time.Time, calendarEvent *fleet.CalendarEvent, hostCalendarEvent *fleet.HostCalendarEvent) bool {
|
||||
// Check the user calendar every 30 minutes (and not every cron run)
|
||||
// to reduce load on both Fleet and the calendar service.
|
||||
if time.Since(calendarEvent.UpdatedAt) > 30*time.Minute {
|
||||
return true
|
||||
}
|
||||
// If the event is supposed to be happening now, we want to check if the user moved/deleted the
|
||||
// event on the last minute.
|
||||
if eventHappeningNow(now, calendarEvent) && hostCalendarEvent.WebhookStatus == fleet.CalendarWebhookStatusNone {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func eventHappeningNow(now time.Time, calendarEvent *fleet.CalendarEvent) bool {
|
||||
return !now.Before(calendarEvent.StartTime) && now.Before(calendarEvent.EndTime)
|
||||
}
|
||||
|
||||
func sameDate(t1 time.Time, t2 time.Time) bool {
|
||||
y1, m1, d1 := t1.Date()
|
||||
y2, m2, d2 := t2.Date()
|
||||
|
|
|
|||
Loading…
Reference in a new issue