github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/notify/task_completion_handler.go (about)

     1  package notify
     2  
     3  import (
     4  	"github.com/evergreen-ci/evergreen"
     5  	"github.com/evergreen-ci/evergreen/model/task"
     6  	"github.com/evergreen-ci/evergreen/web"
     7  	"github.com/mongodb/grip"
     8  )
     9  
    10  // Handler for task completion notifications, i.e. send notifications whenever
    11  // a task finishes. Implements NotificationHandler from notification_handler.go.
    12  type TaskCompletionHandler struct {
    13  	TaskNotificationHandler
    14  	Name string
    15  }
    16  
    17  func (self *TaskCompletionHandler) GetNotifications(ae *web.App, key *NotificationKey) ([]Email, error) {
    18  	var emails []Email
    19  	preface := mciCompletionPreface
    20  	if key.NotificationRequester == evergreen.PatchVersionRequester {
    21  		preface = patchCompletionPreface
    22  	}
    23  	triggeredNotifications, err :=
    24  		self.getRecentlyFinishedTasksWithStatus(key, "", preface, completionSubject)
    25  
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	for _, triggered := range triggeredNotifications {
    31  		email, err := self.TemplateNotification(ae, &triggered)
    32  		if err != nil {
    33  			grip.Noticef("template error with task completion notification for '%s': %s",
    34  				triggered.Current.Id, err.Error())
    35  			continue
    36  		}
    37  
    38  		emails = append(emails, email)
    39  	}
    40  
    41  	return emails, nil
    42  }
    43  
    44  func (self *TaskCompletionHandler) TemplateNotification(ae *web.App, notification *TriggeredTaskNotification) (Email, error) {
    45  	changeInfo, err := self.GetChangeInfo(notification)
    46  	if err != nil {
    47  		return nil, err
    48  	}
    49  	return self.templateNotification(ae, notification, changeInfo)
    50  }
    51  
    52  func (self *TaskCompletionHandler) GetChangeInfo(
    53  	notification *TriggeredTaskNotification) ([]ChangeInfo, error) {
    54  	return self.constructChangeInfo([]task.Task{*notification.Current}, &notification.Key)
    55  }