The ShouldBeUnique interface will be used by Laravel to determine if the job should be unique and saves the unique id. This always uses a cache repository and therefore is not cleared after queue:clear.
If a job does not need to run anymore given a certain condition, it will be the easiest to return early. An example for this would be to stop executing a job from a cancelled batch.
public function handle(): void
{
if ($cancel) {
return;
}
// ...
}
Laravel will automatically remove the unique cache key of the job if it has finished executing. Note that if you kill the process before the job is finished, with a dd for example, you will have to clear the cache yourself.