spacecatninja / craft-imager-x-do-spaces-driver

External storage driver for Imager X that integrates with DigitalOcean Spaces
MIT License
2 stars 1 forks source link

Auto-generation of transforms failing and blocking queue #3

Open cole007 opened 4 months ago

cole007 commented 4 months ago

We have just launched a client site using DO Spaces and Imager X and auto-generation of transforms is failing and blocking the queue (therefore preventing other jobs from executing such as email delivery, etc).

It looks like the job is trying to read from/write to a file path but is not specifying the URL for this, just the path so is throwing a "Failed to open stream: No such file or directory". Obviously we can set optimizeType to runtime to avoid this blocking the queue but wondering if you had some insight on why this is happening.

Craft CMS v4.9.4 Imager X v4.4.0 Digital Ocean Spaces v2.0.0 Imager X for Digital Ocean Spaces v3.0.0

PHP v8.3.7

Relevant Config

'optimizeType' => 'runtime',
'optimizerConfig' => [
    'jpegtran' => [
        'extensions' => ['jpg'],
        'path' => '/usr/bin/jpegtran',
    'optionString' => '-optimize -copy none -progressive',
    ],
    'optipng' => [
        'extensions' => ['png'],
        'path' => '/usr/bin/optipng',
        'optionString' => '-o5 -strip all',
    ],
    'gifsicle' => [
        'extensions' => ['gif'],
        'path' => '/usr/bin/gifsicle',
        'optionString' => '--optimize=3 --colors 128',
    ],
],
'optimizers' => ['jpegtran', 'optipng', 'gifsicle'],
'storages' => ['dospaces'],
'storageConfig' => [
    'dospaces'  => [
        'endpoint' => getenv('SPACES_ENDPOINT'),
    'accessKey' => getenv('SPACES_ACCESS_KEY'),
    'secretAccessKey' => getenv('SPACES_SECRET_KEY'),
    'region' => getenv('SPACES_REGION'),
    'bucket' => getenv('SPACES_BUCKET'),
    'folder' => 'transforms',
    'requestHeaders' => array(),
    ]
],

Error:

2024-05-31 10:33:06 [queue.ERROR] [spacecatninja\imagerx\optimizers\JpegtranOptimizer::optimize] Optimizer spacecatninja\imagerx\optimizers\JpegtranOptimizer could not be found in path /usr/bin/jpegtran {"memory":3823888} 
2024-05-31 10:33:06 [queue.ERROR] [craft\queue\QueueLogBehavior::afterError]  [11727] Optimizing images (jpegtran) (attempt: 1, pid: 3354) - Error (time: 0.007s): fopen(transforms/uploads/Partners/4821/Philippa-Headshot_ce20755dda590f729c05aedf39db1575.jpg): Failed to open stream: No such file or directory {"memory":3874864} 
2024-05-31 10:33:06 [queue.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: fopen(transforms/uploads/Partners/4821/Philippa-Headshot_ce20755dda590f729c05aedf39db1575.jpg): Failed to open stream: No such file or directory in /var/www/html/deploy/vendor/spacecatninja/imager-x-do-spaces-driver/src/externalstorage/DOSpacesStorage.php:73

Stack Trace:

#0 /var/www/html/deploy/vendor/craftcms/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError()
#1 [internal function]: craft\web\ErrorHandler->handleError()
#2 /var/www/html/deploy/vendor/spacecatninja/imager-x-do-spaces-driver/src/externalstorage/DOSpacesStorage.php(73): fopen()
#3 /var/www/html/deploy/vendor/spacecatninja/imager-x/src/services/StorageService.php(52): spacecatninja\imagerxdospacesdriver\externalstorage\DOSpacesStorage::upload()
#4 /var/www/html/deploy/vendor/spacecatninja/imager-x/src/jobs/OptimizeJob.php(69): spacecatninja\imagerx\services\StorageService->store()
#5 /var/www/html/deploy/vendor/yiisoft/yii2-queue/src/Queue.php(243): spacecatninja\imagerx\jobs\OptimizeJob->execute()
#6 /var/www/html/deploy/vendor/yiisoft/yii2-queue/src/cli/Queue.php(147): yii\queue\Queue->handleMessage()
#7 /var/www/html/deploy/vendor/craftcms/cms/src/queue/Queue.php(191): yii\queue\cli\Queue->handleMessage()
#8 /var/www/html/deploy/vendor/craftcms/cms/src/queue/Queue.php(166): craft\queue\Queue->executeJob()
#9 [internal function]: craft\queue\Queue->craft\queue\{closure}()
#10 /var/www/html/deploy/vendor/yiisoft/yii2-queue/src/cli/Queue.php(114): call_user_func()
#11 /var/www/html/deploy/vendor/craftcms/cms/src/queue/Queue.php(164): yii\queue\cli\Queue->runWorker()
#12 /var/www/html/deploy/vendor/craftcms/cms/src/controllers/QueueController.php(82): craft\queue\Queue->run()
#13 /var/www/html/deploy/vendor/craftcms/cms/src/controllers/QueueController.php(103): craft\controllers\QueueController->actionRun()
#14 [internal function]: craft\controllers\QueueController->actionRetry()
#15 /var/www/html/deploy/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#16 /var/www/html/deploy/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#17 /var/www/html/deploy/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#18 /var/www/html/deploy/vendor/craftcms/cms/src/web/Application.php(340): yii\base\Module->runAction()
#19 /var/www/html/deploy/vendor/craftcms/cms/src/web/Application.php(641): craft\web\Application->runAction()
#20 /var/www/html/deploy/vendor/craftcms/cms/src/web/Application.php(302): craft\web\Application->_processActionRequest()
#21 /var/www/html/deploy/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#22 /var/www/html/deploy/public/index.php(21): yii\base\Application->run()
#23 {main} {"memory":3875136,"exception":"[object] (yii\\base\\ErrorException(code: 2): fopen(transforms/uploads/Partners/4821/Philippa-Headshot_ce20755dda590f729c05aedf39db1575.jpg): Failed to open stream: No such file or directory at /var/www/html/deploy/vendor/spacecatninja/imager-x-do-spaces-driver/src/externalstorage/DOSpacesStorage.php:73)"} 
aelvan commented 4 months ago

Hi,

The initial error, JpegtranOptimizer could not be found in path /usr/bin/jpegtran, indicates that Imager can't find jpegtran at the given path, or that PHP can't see it (due to permissions). Have you checked that it's actually installed on the server? If yes, you can try setting the skipExecutableExistCheck config setting to true, which will just bypass the file_exists() check and try to run the command anyway.