Open genivaldosilva opened 8 months ago
@genivaldosilva sorry for my late reply. I noticed that you are using Elasticsearch server version 7.17.13
and elasticsearch-php version 8.10
. You should use the latest version 7.17.2 of elasticsearch-php since you are using servion 7 of the server.
Please try and let me know, thanks.
Hi @ezimuel! Same problem.
Summary of problem or feature request
Logs from an asynchronous job in a Laravel queue are not sent to Elasticsearch until you shutdown the queue process.
This is because the
php artisan queue:work
does not close the process. Queue workers do not "reboot" the framework before processing each job.Code snippet of problem
How to reproduce
declare(strict_types=1);
namespace App\Logging;
use Elastic\Elasticsearch\ClientBuilder; use Monolog\Handler\ElasticsearchHandler; use Monolog\Logger;
class CreateElasticsearchLogger { /**
Create a custom Monolog instance. */ public function __invoke(array $config): Logger { $hosts = ['host-to-elastic:9200']; $username = 'elastic'; $password = 'password'; $index = 'your-index-name'; $type = '_doc';
} }
declare(strict_types=1);
namespace App\Jobs;
use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log;
class TestJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
}
.env
QUEUE_CONNECTION=redis
Call GET![Screenshot from 2023-10-20 08-55-32](https://github.com/elastic/elasticsearch-php/assets/7896224/0b68d72d-89bc-4fe0-8bbe-11735245bc0b)
/test-log
You'll see:Call GET
/test-log-job
You won't see, but when you kill the process:You will receive the log:![Screenshot from 2023-10-20 08-59-47](https://github.com/elastic/elasticsearch-php/assets/7896224/fdec3b29-d23c-49b5-935a-b39c1793add6)
System details
8.2
^8.10
elasticsearch:7.17.13