'Laravel - DB::Transaction + API Call - General error: 1205 Lock wait timeout exceeded; try restarting transaction

I have a block of code like this in Laravel:

try {
    DB::beginTransaction();

    $session = $this->createOrUpdateSession('2022-02-02');

    Guzzl::post('/whatsapp/v2/id/' . $session, ['sessionId' => $session]);

    $this->pay($session);

    DB::commit();
} catch (Exception $e) {
    DB::rollback();
}

But the problem is that this WhatsApp (for example) API call usually takes 10 seconds and then the whole database will be waiting for this and on the large scale it throws this error:

General error: 1205 Lock wait timeout exceeded; try restarting transaction

What can I do?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source