-
Hi Community! I'm using Jobs to interact with an API which is hardly rate limited. There are multiple Jobs that do things one after all (fetch projects, fetch customers, fetch working time entries, calculate project progress etc...) These jobs should never overlap globally (never fetch customers while another job of the chain is running), so I used the middleware WIthoutOverlapping (https://laravel.com/docs/8.x/queues#preventing-job-overlaps) and the same key for all Jobs like this: public function middleware()
{
return [
(new WithoutOverlapping("dont-overlap")),
];
} So far, so good. But after that, it was still running into rate limits. After some investigation I detected, that the Middleware is always bound to the Job it is used in. This is caused by the following function in the WithoutOverlapping middleware: /**
* Get the lock key for the given job.
*
* @param mixed $job
* @return string
*/
public function getLockKey($job)
{
return $this->prefix.get_class($job).':'.$this->key;
} The problem is caused by This is also not clear when reading the Docs IMHO. Of course, I can create my very own variant of this middleware and change this behaviour. But could we not have the middleware renamed to e.g. WithoutOverlappingByJob? As this would be a braking change in some cases it could also make sense to create a new middleware e.g. WithoutGlobalOverlapping and note this behaviour in the docs to make this even more clear? What do you think? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I agree that something needs to change or be clarified here. I was going to use I can think of two different code options that wouldn't be a breaking change. The first is to create a public function middleware()
{
return [(new WithoutOverlapping($this->user->id))->globally()];
} If a global key option is not desired, I think the documentation should at least be clarified. It currently states the following:
"Arbitrary" and the example of using I'd be glad to submit a PR for a code and/or documentation change. Just let me know! I personally am leaning towards a |
Beta Was this translation helpful? Give feedback.
-
This thread is very outdated. Will close it. As @SCIF said -> #44227. Docs can be found here: https://laravel.com/docs/10.x/queues#sharing-lock-keys |
Beta Was this translation helpful? Give feedback.
This thread is very outdated. Will close it. As @SCIF said -> #44227.
Docs can be found here: https://laravel.com/docs/10.x/queues#sharing-lock-keys