Skip to content

Commit

Permalink
[ui] Show "Scaled Down" as a valid job status when task groups' count…
Browse files Browse the repository at this point in the history
…s are set to zero (#23829)

* Scaled Down as a status

* Scaled Down as a steady-state job panel status as well

* Test for badge status and changelog
  • Loading branch information
philrenaud authored Aug 19, 2024
1 parent 4aeb279 commit 5fcec1f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/23829.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Badge added for Scaled Down jobs
```
9 changes: 8 additions & 1 deletion ui/app/components/job-status/panel/steady.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default class JobStatusPanelSteadyComponent extends Component {

/**
* @typedef {Object} CurrentStatus
* @property {"Healthy"|"Failed"|"Degraded"|"Recovering"|"Complete"|"Running"|"Stopped"} label - The current status of the job
* @property {"Healthy"|"Failed"|"Degraded"|"Recovering"|"Complete"|"Running"|"Stopped"|"Scaled Down"} label - The current status of the job
* @property {"highlight"|"success"|"warning"|"critical"|"neutral"} state -
*/

Expand All @@ -224,6 +224,13 @@ export default class JobStatusPanelSteadyComponent extends Component {
};
}

if (this.totalAllocs === 0) {
return {
label: 'Scaled Down',
state: 'neutral',
};
}

if (this.job.type === 'batch' || this.job.type === 'sysbatch') {
// If all the allocs are complete, the job is Complete
const completeAllocs = this.allocBlocks.complete?.healthy?.nonCanary;
Expand Down
9 changes: 8 additions & 1 deletion ui/app/models/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class Job extends Model {

/**
* @typedef {Object} CurrentStatus
* @property {"Healthy"|"Failed"|"Deploying"|"Degraded"|"Recovering"|"Complete"|"Running"|"Removed"|"Stopped"} label - The current status of the job
* @property {"Healthy"|"Failed"|"Deploying"|"Degraded"|"Recovering"|"Complete"|"Running"|"Removed"|"Stopped"|"Scaled Down"} label - The current status of the job
* @property {"highlight"|"success"|"warning"|"critical"|"neutral"} state -
*/

Expand Down Expand Up @@ -226,6 +226,7 @@ export default class Job extends Model {
* - Failed: All allocations are failed, lost, or unplaced
* - Removed: The job appeared in our initial query, but has since been garbage collected
* - Stopped: The job has been manually stopped (and not purged or yet garbage collected) by a user
* - Scaled Down: The job is intentionally scaled down to 0 desired allocations (all task groups have count=0)
* @returns {CurrentStatus}
*/
/**
Expand All @@ -248,6 +249,12 @@ export default class Job extends Model {
};
}

// If the job is scaled down to 0 desired allocations, we shouldn't call it "failed";
// we should indicate that it is deliberately set to not have any running parts.
if (totalAllocs === 0) {
return { label: 'Scaled Down', state: 'neutral' };
}

// If the job was requested initially, but a subsequent request for it was
// not found, we can remove links to it but maintain its presence in the list
// until the user specifies they want a refresh
Expand Down
2 changes: 1 addition & 1 deletion ui/mirage/factories/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export default Factory.extend({
groupProps.taskCount = job.groupTaskCount;
}

if (job.groupAllocCount) {
if (job.groupAllocCount !== undefined) {
groupProps.count = job.groupAllocCount;
}

Expand Down
10 changes: 10 additions & 0 deletions ui/tests/acceptance/jobs-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,13 @@ module('Acceptance | jobs list', function (hooks) {
activeDeployment: true,
});

server.create('job', {
...defaultJobParams,
id: 'scaled-down-job',
groupAllocCount: 0,
status: 'dead',
});

await JobsList.visit();

assert
Expand Down Expand Up @@ -732,6 +739,9 @@ module('Acceptance | jobs list', function (hooks) {
assert
.dom('[data-test-job-row="deploying-job"] [data-test-job-status]')
.hasText('Deploying', 'Deploying job is deploying');
assert
.dom('[data-test-job-row="scaled-down-job"] [data-test-job-status]')
.hasText('Scaled Down', 'Scaled down job is scaled down');

await percySnapshot(assert);
});
Expand Down

0 comments on commit 5fcec1f

Please sign in to comment.