TL;DR: How can I return data from a queued Job without saving it anywhere and handling the situation when the job might run more than once because of retries? Or is there another way if Jobs are not suitable for this?
I am developing API on Laravel for mobile application.
Methods will make requests to other API's, combine and filter data, changing it's structure etc.
One of the requirements to app is to respond no more than 30 seconds, or not respond at all. So, I have to repeat requests as much as I have time. I trying to realize that with Laravel Queues, and currently have something like that in my Job class:
private $apiActionName;
public function __construct($apiActionName)
{
$this->apiActionName = $apiActionName;
}
public function handle(SomeService $someService)
{
return $someService->{$this->apiActionName}();
}
And this action code in controller:
public function someAction()
{
$data = $this->dispatch(new MyJob($apiActionName));
return response()->json($data);
}
Yes, I know it is bad idea to return value from job, but expect that it's possible. However $this->dispatch()
returns only queued job ID, not result of handle
method.