ui: Only show paused icon when allocs in pending state are paused. (#25742)

Jobs were being marked incorectly as having paused allocations
when termimal allocations were marked with the paused boolean. The
UI should only mark a job as including paused allocations when
these paused allocations are in the correct client state, which is
pending.

---------

Co-authored-by: Phil Renaud <phil@riotindustries.com>
This commit is contained in:
James Rasell
2025-04-25 07:45:45 +01:00
committed by GitHub
parent 374e987b9b
commit e928131482
6 changed files with 38 additions and 12 deletions

View File

@@ -316,15 +316,20 @@ export default class Job extends Model {
@attr('boolean') isPack;
/**
* A task with a schedule block can have execution paused at specific cron-based times.
* If one is currently paused, an allocation at /statuses will come back with hasPausedTask=true.
* We should represent this to the user in the job row.
* A task with a schedule block can have execution paused at specific
* cron-based times. If an allocation is currently paused and in a pending
* client state, we should represent this to the user in the job row.
*
* Use the allocations client status and the hasPausedTask allocation returned
* at /statuses to determine the correct information.
*/
get hasPausedTask() {
if (!this.allocations) {
return false;
}
return this.allocations.any((alloc) => alloc.hasPausedTask);
return this.allocations
.filter((alloc) => alloc.clientStatus === 'pending')
.any((alloc) => alloc.hasPausedTask);
}
// True when the job is the parent periodic or parameterized jobs

View File

@@ -229,8 +229,7 @@ export default Factory.extend({
});
allocation.update({
taskStateIds:
allocation.clientStatus === 'pending' ? [] : states.mapBy('id'),
taskStateIds: states.mapBy('id'),
taskResourceIds: resources.mapBy('id'),
});

View File

@@ -173,6 +173,23 @@ function smallCluster(server) {
state: 'running',
});
const pausedJobGroups = 2;
const pausedTasksPerGroup = 5;
server.create('job', {
name: 'paused-job',
id: 'paused-job',
namespaceId: 'default',
type: 'service',
withPausedTasks: true,
resourceSpec: Array(pausedJobGroups).fill('M: 256, C: 500'),
groupTaskCount: pausedTasksPerGroup,
shallow: false,
allocStatusDistribution: {
pending: 1,
},
noActiveDeployment: true,
});
server.create('policy', {
id: 'client-reader',
name: 'client-reader',

View File

@@ -289,9 +289,10 @@ module('Acceptance | allocation detail', function (hooks) {
});
test('when there are no tasks, an empty state is shown', async function (assert) {
// Make sure the allocation is pending in order to ensure there are no tasks
allocation = server.create('allocation', 'withTaskWithPorts', {
clientStatus: 'pending',
allocation = server.create('allocation');
allocation.update({
taskStateIds: [],
taskResourceIds: [],
});
await Allocation.visit({ id: allocation.id });

View File

@@ -767,7 +767,7 @@ module('Acceptance | jobs list', function (hooks) {
createAllocations: true,
});
server.create('job', {
name: 'time-based-job ',
name: 'time-based-job',
id: 'time-based-job',
createAllocations: true,
type: 'service',
@@ -777,10 +777,11 @@ module('Acceptance | jobs list', function (hooks) {
groupAllocCount: 1,
groupTaskCount: 1,
allocStatusDistribution: {
running: 1,
pending: 1,
},
noActiveDeployment: true,
status: 'running',
status: 'pending',
clientStatus: 'pending',
noFailedPlacements: true,
});