Web: clarify the cluster assignment result in the worker details view

Now the hint is no longer generically explaining things, but is dynamic
and specific for the current assignment of the worker's clusters.
This commit is contained in:
Sybren A. Stüvel 2023-04-04 13:21:12 +02:00
parent 10d7e7e203
commit a36c4cd4e4

View File

@ -43,8 +43,11 @@
</switch-checkbox> </switch-checkbox>
</li> </li>
</ul> </ul>
<p class="hint"> <p class="hint" v-if="hasClustersAssigned">
When a worker is assigned to one or more cluster, it will ignore jobs assigned to other clusters. This worker will only pick up jobs assigned to one of its clusters, and clusterless jobs.
</p>
<p class="hint" v-else>
This worker will only pick up clusterless jobs.
</p> </p>
</section> </section>
@ -207,6 +210,10 @@ export default {
workerSleepScheduleStatusLabel() { workerSleepScheduleStatusLabel() {
return this.workerSleepSchedule.is_active ? 'Enabled' : 'Disabled'; return this.workerSleepSchedule.is_active ? 'Enabled' : 'Disabled';
}, },
hasClustersAssigned() {
const clusterIDs = this.getAssignedClusterIDs();
return clusterIDs && clusterIDs.length > 0;
}
}, },
methods: { methods: {
fetchWorkerSleepSchedule() { fetchWorkerSleepSchedule() {
@ -272,15 +279,10 @@ export default {
console.log("New assignment:", plain(this.thisWorkerClusters)) console.log("New assignment:", plain(this.thisWorkerClusters))
// Construct cluster change request. // Construct cluster change request.
const clusterIDs = []; const clusterIDs = this.getAssignedClusterIDs();
for (clusterID in this.thisWorkerClusters) { const changeRequest = new WorkerClusterChangeRequest(clusterIDs);
// Values can exist and be set to 'false'.
const isAssigned = this.thisWorkerClusters[clusterID];
if (isAssigned) clusterIDs.push(clusterID);
}
// Send to the Manager. // Send to the Manager.
const changeRequest = new WorkerClusterChangeRequest(clusterIDs);
this.api.setWorkerClusters(this.workerData.id, changeRequest) this.api.setWorkerClusters(this.workerData.id, changeRequest)
.then(() => { .then(() => {
this.notifs.add('Cluster assignment updated'); this.notifs.add('Cluster assignment updated');
@ -290,6 +292,15 @@ export default {
this.notifs.add(`Error: ${errorMsg}`); this.notifs.add(`Error: ${errorMsg}`);
}); });
}, },
getAssignedClusterIDs() {
const clusterIDs = [];
for (let clusterID in this.thisWorkerClusters) {
// Values can exist and be set to 'false'.
const isAssigned = this.thisWorkerClusters[clusterID];
if (isAssigned) clusterIDs.push(clusterID);
}
return clusterIDs;
}
} }
}; };
</script> </script>