Feb 9, 2021
0
Level 1
Laravel Queue From API request
Hello to everyone. I have something to ask. I want to perform a function which calls the Queueable Object which stores values into my database. But my problem is that every api request I've made when I used a dispatch it returns: { }
however when every time I used dispatchNow() there's always a response like:
{ "name": "transaction_1" }
My problem is the queue is overlapping and it execute the process at the same time. Can anyone have a suggestion about my problem? Thanks. I used android as my client app.
here is my controller code below:
$validated = $request->validate([
'data' => 'required|array'
]);
$job = new ProcessTransaction($validated);
$data = $this->dispatchNow($job);
return response()->json(get_object_vars($job->getResponse())['original']);
my Queueable Class looks like:
public $tries = 1;
protected $data;
public function __construct(array $data)
{
$this->data= $data;
}
public function uniqueId()
{
return $this->data['name'];
}
public function middleware()
{
return [new WithoutOverlapping($this->data['name'])];
}
public function handle()
{
$transaction = Transaction::create(['name' => $this->data['name']]);
if (!$transaction)
$this->response = response(["message" => "error"], 400);
else
$this->response = response(['message' => 'accepted'], 200);
}
public function getResponse()
{
return $this->response;
}
Please or to participate in this conversation.