github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/event/scheduler_event.go (about) 1 package event 2 3 import ( 4 "time" 5 6 "github.com/mongodb/grip" 7 ) 8 9 const ( 10 // resource type 11 ResourceTypeScheduler = "SCHEDULER" 12 13 // event types 14 EventSchedulerRun = "SCHEDULER_RUN" 15 ) 16 17 type TaskQueueInfo struct { 18 TaskQueueLength int `bson:"tq_l" json:"task_queue_length"` 19 NumHostsRunning int `bson:"n_h" json:"num_hosts_running"` 20 ExpectedDuration time.Duration `bson:"ex_d" json:"expected_duration,"` 21 } 22 23 // implements EventData 24 type SchedulerEventData struct { 25 // necessary for IsValid 26 ResourceType string `bson:"r_type" json:"resource_type"` 27 TaskQueueInfo TaskQueueInfo `bson:"tq_info" json:"task_queue_info"` 28 DistroId string `bson:"d_id" json:"distro_id"` 29 } 30 31 func (sed SchedulerEventData) IsValid() bool { 32 return sed.ResourceType == ResourceTypeScheduler 33 } 34 35 // LogSchedulerEvent takes care of logging the statistics about the scheduler at a given time. 36 // The ResourceId is the time that the scheduler runs. 37 func LogSchedulerEvent(eventData SchedulerEventData) { 38 eventData.ResourceType = ResourceTypeScheduler 39 event := Event{ 40 Timestamp: time.Now(), 41 ResourceId: eventData.DistroId, 42 EventType: EventSchedulerRun, 43 Data: DataWrapper{eventData}, 44 } 45 46 logger := NewDBEventLogger(AllLogCollection) 47 if err := logger.LogEvent(event); err != nil { 48 grip.Errorf("Error logging host event: %+v", err) 49 } 50 }