The AssetContainerContents
are not updated when creating an asset in a job. This results in the job failing. This bug sounds pretty similar to statamic/cms#5501 and should have been closed by statamic/cms#6726.
STATAMIC_STACHE_WATCHER=false
QUEUE_CONNECTION=redis
Also, make sure to create and migrate a database so that failed jobs can be logged.
- Create a user
- Run
php artisan queue:work
in your terminal - Login to the CP, go to the pages collection, and switch to the list view
- Open the contextual menu of an entry and run the
Import Data
action
You should now see the App\Actions\ImportImage
and Statamic\Listeners\GeneratePresetImageManipulations
jobs fail:
![CleanShot 2024-03-08 at 12 24 59@2x](https://private-user-images.githubusercontent.com/23167701/311313110-54255e77-df6f-4316-8306-213e613a95aa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNTczNDYsIm5iZiI6MTczOTI1NzA0NiwicGF0aCI6Ii8yMzE2NzcwMS8zMTEzMTMxMTAtNTQyNTVlNzctZGY2Zi00MzE2LTgzMDYtMjEzZTYxM2E5NWFhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDA2NTcyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE1MjU3NWQ2MDI5MDQ0NGZlNjE4NTg0ZDEzOTBhY2VmNzBlZmEwNTA2YjFlNTUxMjg5Yjg3YjYwYTVkYzk5OWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.RPhj2G_Yntd5PDicKcQze1tbM7Ass9rvbRuQTadfIVw)
![CleanShot 2024-03-08 at 12 22 17@2x](https://private-user-images.githubusercontent.com/23167701/311312196-b04d21eb-be72-4f73-a457-09e597bd258b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNTczNDYsIm5iZiI6MTczOTI1NzA0NiwicGF0aCI6Ii8yMzE2NzcwMS8zMTEzMTIxOTYtYjA0ZDIxZWItYmU3Mi00ZjczLWE0NTctMDllNTk3YmQyNThiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDA2NTcyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI1ZjdlNDFkYTNmMzc0NzZiMGQ3NThkYWVhNmFiYmRiYTZlZWEyN2IzNGNkYWI2MWIzYmE0ODQ4MWUzZTdlZGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.9H1hiK_k6hfjOlJhXSvWzGcLSR05TCOXSxr6Xr6Dy9s)
These exceptions make sense when you look at the asset container contents. You can confirm that the newly created asset is missing from the list by opening up a Tinkerwell session and getting the contents of the asset container.
![CleanShot 2024-03-08 at 12 41 13@2x](https://private-user-images.githubusercontent.com/23167701/311317211-d4a25901-0e53-421b-a9af-e33676b67730.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNTczNDYsIm5iZiI6MTczOTI1NzA0NiwicGF0aCI6Ii8yMzE2NzcwMS8zMTEzMTcyMTEtZDRhMjU5MDEtMGU1My00MjFiLWE5YWYtZTMzNjc2YjY3NzMwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDA2NTcyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ3YzEzNjVjOThlYTgyMTE5NDlmODA3ZDRhMTdjZTgyNDFiNmM5N2FlZmI2MTVlZTBjODM3OWI0MWZiYjgyMjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.GKytuv5kDBW-oV0tvct8_hNUGe7tL4ZYgEUk9vGzClQ)
The asset container contents are cached in the all()
method of the AssetContainerContents
class. When running a queue, this cache is used on subsequent calls to the method.
Now when an asset is saved in the save()
method of the AssetRepository
class, its path is added to the cached container contents. But when the save()
method on the AssetContainerContents
is called, the cached instance doesn't include the newly added path.
There seems to be an easy fix by explicitly adding the new path to the cache:
public function add($path)
{
if (! $metadata = $this->getNormalizedFlysystemMetadata($path)) {
return $this;
}
// Add parent directories
if (($dir = dirname($path)) !== '.') {
$this->add($dir);
}
- $this->all()->put($path, $metadata);
+ $files = $this->all()->put($path, $metadata);
+
+ if (Statamic::isWorker()) {
+ Cache::put($this->key(), $files, $this->ttl());
+ }
$this->filteredFiles = null;
$this->filteredDirectories = null;
return $this;
}