package models import ( "fmt" "oc-scheduler/logger" "sync" "time" ) // Is duration really important ? type Booking struct { Start time.Time Stop time.Time Duration uint Workflow string } type ScheduledBooking struct { Bookings []Booking Mu sync.Mutex } func (s Booking) Equals(other Booking) bool { return s.Workflow == other.Workflow && s.Start == other.Start && s.Stop == other.Stop } func (sb *ScheduledBooking) AddSchedule(new_booking Booking){ if(!sb.scheduleAlreadyExists(new_booking)){ sb.Bookings = append(sb.Bookings,new_booking) logger.Logger.Info().Msg("Updated list schedules : \n " + sb.String()) } else { // Debug condition : delete once this feature is ready to be implemented logger.Logger.Debug().Msg("Workflow received not added, current schedule contains") for _, booking := range(sb.Bookings){ logger.Logger.Debug().Msg(booking.String()) } } } func (sb *ScheduledBooking) GetListNames()(list_names []string ){ for _, schedule := range(sb.Bookings){ list_names = append(list_names, schedule.Workflow) } return } func (sb *ScheduledBooking) scheduleAlreadyExists(new_booking Booking) bool { for _, booking := range(sb.Bookings){ if booking.Equals(new_booking){ return true } } return false } func (b *Booking) String() string { return fmt.Sprintf("{Workflow : %s , startDate : %s , stopDate : %s }", b.Workflow, b.Start.Format(time.RFC3339), b.Stop.Format(time.RFC3339)) } func (sb *ScheduledBooking) String() string { var str string for _, booking := range(sb.Bookings){ str += fmt.Sprintf("%s\n", booking.String()) } return str }