[13.x] Add isLocked to the Lock class
Currently there isnt a simple way to see if a lock is acquired in general, without tapping into the table.
I want to show an indicator if an item is in the queue, ie "X is in the queue"
My jobs are unique so I wanted to use the lock to know, rather than adding columns or additional cache bits for details that are available.
Currently, this ends up looking like this
return DB::table('cache_locks')
->where('key', UniqueLock::getKey(new ItemJob($this->id)))
->exists();
But, its not store agnostic and nasty, I'd like to be able to something like:
return Cache::lock(UniqueLock::getKey(new ItemJob($this->id)))->isLocked();
Which is what this PR does! The main thing here is it doesn't acquire the lock, its just for knowing if its currently locked.
The debounce lock already has something similar, so I brought it up to the abstract for the other locks... essentially https://github.com/laravel/framework/blob/79d24c863438e322f45384c29421f7b0106f4560/src/Illuminate/Bus/DebounceLock.php#L105
You also cant access getCurrentOwner.. but open to making that public if you would rather? which means we dont get:
Error: Call to protected method Illuminate\Cache\xxxx::getCurrentOwner() from scope yyy
Open to renaming etc... maybe isAcquired is better? I wanted to use the InspectedJob class, but the uniqueId is hidden in the payload context, so feels.. weird that way.
Maybe you see a magical way or better way for doing this though?
I'll tighten up the contract in 14.x potentially, if this is accepted!