I'm building an API using Laravel that has an endpoint /api/keyword
. Clients can use that API to request statistics about given keywords (provided as a query parameter). Those statistics are coming from a 3rd party service that has uses throttling (max. 3 requests per minute) and only accepts 100 keywords at a time. Hence, I would like to reduce requests (to the 3rd party API) by potentially combining keywords coming from multiple requests (from the client).
I've implemented a job called FetchKeywordStatistics
which is dispatched in the API controller like this:
FetchKeywordStatistics::dispatch($keywords); // $keywords being [Keyword, Keyword, ...]
Ideally, what I would like to achieve is when the queue is picking up a job, it looks at other queued jobs and optionally merge those jobs by combining the keywords and making a single request to the 3rd party service.
Is this somehow possible?