Skip to content

Commit

Permalink
feat(cd): add run time to notifs
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 committed Nov 9, 2023
1 parent 4167ea1 commit ca195ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions cd/manager/notifs/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
const (
notifField_References string = "References"
notifField_JobId string = "Job ID"
notifField_Time string = "Time"
notifField_RunTime string = "Time Running"
notifField_Deploy string = "Deployment(s)"
notifField_Anchor string = "Anchor Worker(s)"
notifField_TestE2E string = "E2E Tests"
Expand Down Expand Up @@ -151,10 +151,18 @@ func (n JobNotifs) getNotifFields(jobState job.JobState) []discord.EmbedField {
Value: deployTags,
})
}
fields = append(fields, discord.EmbedField{
Name: notifField_Time,
Value: time.Now().Format(time.RFC1123), // "Mon, 02 Jan 2006 15:04:05 MST"
})
if startTime, found := jobState.Params[job.JobParam_Start].(float64); found {
runTime := time.Since(time.Unix(0, int64(startTime)))
hours := int(runTime.Seconds() / 3600)
minutes := int(runTime.Seconds()/60) % 60
seconds := int(runTime.Seconds()) % 60
if (hours != 0) || (minutes != 0) || (seconds != 0) {
fields = append(fields, discord.EmbedField{
Name: notifField_RunTime,
Value: fmt.Sprintf("%dh %dm %ds", hours, minutes, seconds),
})
}
}
// Add the list of jobs in progress
if activeJobs := n.getActiveJobs(jobState); len(activeJobs) > 0 {
fields = append(fields, activeJobs...)
Expand Down
6 changes: 3 additions & 3 deletions cd/manager/notifs/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ jobNotif = &workflowNotif{}

const defaultWorkflowJobName = "Workflow"
const (
workflowNotifField_Ref = "Ref"
workflowNotifField_Branch = "Branch"
workflowNotifField_TestSelector = "Test Selector"
workflowNotifField_Logs = "Logs"
)
Expand Down Expand Up @@ -59,8 +59,8 @@ func (w workflowNotif) getTitle() string {
func (w workflowNotif) getFields() []discord.EmbedField {
notifFields := []discord.EmbedField{
{
Name: workflowNotifField_Ref,
Value: fmt.Sprintf("[%s](https://github.com/%s/%s/tree/%s)", w.workflow.Ref, w.workflow.Org, w.workflow.Repo, w.workflow.Ref),
Name: workflowNotifField_Branch,
Value: fmt.Sprintf("[%s (%s)](https://github.com/%s/%s/tree/%s)", w.workflow.Repo, w.workflow.Ref, w.workflow.Org, w.workflow.Repo, w.workflow.Ref),
},
}
// If this is a test workflow, also report the test selector.
Expand Down

0 comments on commit ca195ca

Please sign in to comment.