Support pausing jobs #104313
@ -23,11 +23,11 @@ export const useTasks = defineStore('tasks', {
|
||||
const jobs = useJobs();
|
||||
const activeJob = jobs.activeJob;
|
||||
|
||||
// Check if the job status is 'pause-requested'
|
||||
// Check if the job status is 'pause-requested'.
|
||||
if (activeJob && activeJob.status === 'pause-requested') {
|
||||
David-Zhang-10 marked this conversation as resolved
Outdated
|
||||
return false;
|
||||
}
|
||||
// Allow cancellation for specified task statuses
|
||||
// Allow cancellation for specified task statuses.
|
||||
David-Zhang-10 marked this conversation as resolved
Outdated
Sybren A. Stüvel
commented
Make comments proper sentences, so end with a period. Make comments proper sentences, so end with a period.
|
||||
return this._anyTaskWithStatus(['queued', 'active', 'soft-failed']);
|
||||
},
|
||||
canRequeue() {
|
||||
|
Loading…
Reference in New Issue
Block a user
There's generally two reasons to test something with an
if
statement:In this case the check for
activeJob
is there to prevent errors when accessingactiveJob.status
in case there is no active job. This mixes the two above reasons, though.Another way to look at this, is asking yourself: does it make sense to even answer the query ("can I cancel the active task?") if there is no active job? If too little information is given, in this particular case we know the task but not the job, is that an error? Or is that a sensible state to be in?
When the front-end is displaying tasks, it should be aware of which job those tasks belong to. If that is not the case, I feel that this is a bug. Such bugs should not be hidden, not be defensively worked around. They should be visible, so that they are easy to recognise as bugs. That way people report them, and we can get them fixed.
All that to say: it's probably better to write something like:
Also the triple
===
is unnecessary. The job status is never going to be something other than a string, and if it's some other type, if it compares equal to"pause-requested"
, it's good enough a reason to disable cancellation of the task.