Skip to content

Commit

Permalink
raise SQL default timeout to 70s avoiding MySQL server has gone away
Browse files Browse the repository at this point in the history
  • Loading branch information
WengerK committed Apr 26, 2024
1 parent 7a54542 commit d9a8e00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/entity_to_text_tika/drush.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ services:
entity_to_text_tika.ocr_warmup_command:
class: \Drupal\entity_to_text_tika\Commands\OcrWarmupCommand
arguments:
- '@database'
- '@entity_type.manager'
- '@entity_to_text_tika.extractor.file_to_text'
- '@entity_to_text_tika.storage.local_file'
Expand Down
16 changes: 15 additions & 1 deletion modules/entity_to_text_tika/src/Commands/OcrWarmupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\entity_to_text_tika\Commands;

use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\entity_to_text_tika\Extractor\FileToText;
use Drupal\entity_to_text_tika\Storage\StorageInterface;
Expand All @@ -21,6 +22,13 @@ class OcrWarmupCommand extends DrushCommands {
*/
public const LIMIT_PAGER = 100;

/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;

/**
* The file storage service.
*
Expand All @@ -45,7 +53,8 @@ class OcrWarmupCommand extends DrushCommands {
/**
* Warmup OCR caches for Tika constructor.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, FileToText $file_to_text, StorageInterface $local_storage) {
public function __construct(Connection $connection, EntityTypeManagerInterface $entity_type_manager, FileToText $file_to_text, StorageInterface $local_storage) {
$this->connection = $connection;
$this->fileStorage = $entity_type_manager->getStorage('file');
$this->fileToText = $file_to_text;
$this->localFileStorage = $local_storage;
Expand Down Expand Up @@ -121,6 +130,11 @@ public function warmup(
$force = (bool) $options['force'];
$dry_run = (bool) $options['dry-run'];

// Raise the database connection timeout to 70 seconds.
// Tika default timeout is 60 seconds therefore having a lower value
// for database timeout may lead to MySQL server has gone away.
$this->connection->query('SET wait_timeout = 70');

$query = $this->fileStorage->getQuery();
$query->accessCheck(FALSE);
if ($fid) {
Expand Down

0 comments on commit d9a8e00

Please sign in to comment.