Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/lib/components/status_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import 'package:http/http.dart' as http;
<td class="task-status-cell" *ngFor="let metaTask of headerRow.allMetaTasks">
<div [ngClass]="getStatusStyle(status.checklist.checklist.commit.sha, metaTask.name)"
(click)="openLog(status.checklist.checklist.commit.sha, metaTask.name)">
{{getAttempts(status.checklist.checklist.commit.sha, metaTask.name)}}
</div>
</td>
</tr>
Expand Down Expand Up @@ -141,6 +142,8 @@ class StatusTable implements OnInit {
String cssClass;
if (taskStatus == 'Succeeded' && attempts > 1) {
cssClass = 'task-succeeded-but-flaky';
} else if (taskStatus == 'New' && attempts > 1) {
cssClass = 'task-underperformed';
} else {
cssClass = statusMap[taskStatus] ?? 'task-unknown';
}
Expand All @@ -166,6 +169,17 @@ class StatusTable implements OnInit {
return taskStatusToCssStyle(taskEntity.task.status, taskEntity.task.attempts);
}

String getAttempts(String sha, String taskName) {
TaskEntity taskEntity = _findTask(sha, taskName);

if (taskEntity == null)
return '';

int attempts = taskEntity.task.attempts;
bool succeededImmediately = attempts == 1 && taskEntity.task.status == 'Succeeded';
return attempts == 0 || succeededImmediately ? '' : '${attempts}';
}

List<String> getAgentStyle(AgentStatus status) {
return [
'agent-chip',
Expand Down
8 changes: 5 additions & 3 deletions app/web/buildStyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,16 @@ td.stats-value {
border-radius: 10px;
height: 20px;
width: 20px;
text-align: center;
color: white;
}

.task-new {
background-color: #CCCCFF;
}
.task-in-progress {
background: linear-gradient(0deg, blue 0%, blue 40%, white 41%, white 59%, blue 60%, blue 100%);;
animation: inProgressAnimation 2s infinite linear;
background-color: blue;
animation: inProgressAnimation 3s infinite linear;
cursor: pointer;
}
.task-succeeded {
Expand Down Expand Up @@ -323,7 +325,7 @@ td.stats-value {
transform: rotateZ(0deg);
}
100% {
transform: rotateZ(180deg);
transform: rotateZ(360deg);
}
}

Expand Down
4 changes: 3 additions & 1 deletion commands/get_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ type BuildStatus struct {
// GetStatus returns current build status.
func GetStatus(c *db.Cocoon, inputJSON []byte) (interface{}, error) {
var err error
checklists, err := c.QueryLatestChecklists()

const maxStatusesToReturn = 50
checklists, err := c.QueryLatestChecklists(maxStatusesToReturn)

if err != nil {
return nil, err
Expand Down
22 changes: 20 additions & 2 deletions commands/reserve_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"cocoon/db"
"encoding/json"
"fmt"
"sort"

"golang.org/x/net/context"

Expand Down Expand Up @@ -86,7 +87,8 @@ func ReserveTask(cocoon *db.Cocoon, inputJSON []byte) (interface{}, error) {
}

func findNextTaskToRun(cocoon *db.Cocoon, agent *db.Agent) (*db.TaskEntity, *db.ChecklistEntity, error) {
checklists, err := cocoon.QueryLatestChecklists()
const maxChecklistsToScan = 20
checklists, err := cocoon.QueryLatestChecklists(maxChecklistsToScan)

if err != nil {
return nil, nil, err
Expand All @@ -110,7 +112,7 @@ func findNextTaskToRun(cocoon *db.Cocoon, agent *db.Agent) (*db.TaskEntity, *db.
// these tasks for agents.
continue
}
for _, taskEntity := range stage.Tasks {
for _, taskEntity := range sortByAttemptCount(stage.Tasks) {
task := taskEntity.Task

if len(task.RequiredCapabilities) == 0 {
Expand Down Expand Up @@ -175,3 +177,19 @@ func allPrimaryStagesSuccessful(stages []*db.Stage) bool {
}
return db.Every(len(stages), func(i int) interface{} { return stages[i] }, isSuccessfulPrimaryOrAnySecondary)
}

// Run tasks with fewest prior attempts first.
func sortByAttemptCount(tasks []*db.TaskEntity) []*db.TaskEntity {
sorted := make([]*db.TaskEntity, len(tasks))
copy(sorted, tasks)
sort.Sort(byAttemptCount(sorted))
return sorted
}

type byAttemptCount []*db.TaskEntity

func (tasks byAttemptCount) Len() int { return len(tasks) }
func (tasks byAttemptCount) Swap(i, j int) { tasks[i], tasks[j] = tasks[j], tasks[i] }
func (tasks byAttemptCount) Less(i, j int) bool {
return tasks[i].Task.Attempts < tasks[j].Task.Attempts
}
7 changes: 4 additions & 3 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (c *Cocoon) GetChecklist(key *datastore.Key) (*ChecklistEntity, error) {

// QueryLatestChecklists queries the datastore for the latest checklists sorted
// by CreateTimestamp in descending order. Returns up to 20 entities.
func (c *Cocoon) QueryLatestChecklists() ([]*ChecklistEntity, error) {
query := datastore.NewQuery("Checklist").Order("-CreateTimestamp").Limit(20)
func (c *Cocoon) QueryLatestChecklists(limit int) ([]*ChecklistEntity, error) {
query := datastore.NewQuery("Checklist").Order("-CreateTimestamp").Limit(limit)
var buffer []*ChecklistEntity
for iter := query.Run(c.Ctx); ; {
var checklist Checklist
Expand Down Expand Up @@ -193,7 +193,8 @@ func (c *Cocoon) QueryAllPendingTasks() ([]*FullTask, error) {
//
// See also IsFinal.
func (c *Cocoon) QueryPendingTasks(taskName string) ([]*FullTask, error) {
checklists, err := c.QueryLatestChecklists()
const maxChecklistsToScan = 20
checklists, err := c.QueryLatestChecklists(maxChecklistsToScan)

if err != nil {
return nil, err
Expand Down