fsjobqueue: make canceling a finished job an error

This mirrors FinishJob(), which also errors when the job is already
finished.
This commit is contained in:
Lars Karlitski 2021-01-05 23:21:48 +01:00 committed by Tom Gundersen
parent 30492bfc60
commit 871c6e9cbb
2 changed files with 4 additions and 3 deletions

View file

@ -298,7 +298,7 @@ func (q *fsJobQueue) CancelJob(id uuid.UUID) error {
}
if !j.FinishedAt.IsZero() {
return nil
return jobqueue.ErrNotRunning
}
j.Canceled = true

View file

@ -299,7 +299,7 @@ func testCancel(t *testing.T, q jobqueue.JobQueue) {
err = q.FinishJob(id, &testResult{})
require.Error(t, err)
// Cancel a finished job, which is a no-op
// Cancel a finished job, which is an error
id = pushTestJob(t, q, "clownfish", nil, nil)
require.NotEmpty(t, id)
r, tok, deps, typ, args, err = q.Dequeue(context.Background(), []string{"clownfish"})
@ -312,7 +312,8 @@ func testCancel(t *testing.T, q jobqueue.JobQueue) {
err = q.FinishJob(id, &testResult{})
require.NoError(t, err)
err = q.CancelJob(id)
require.NoError(t, err)
require.Error(t, err)
require.Equal(t, jobqueue.ErrNotRunning, err)
result, _, _, _, canceled, _, err = q.JobStatus(id)
require.NoError(t, err)
require.False(t, canceled)