mage2tv / magento-cache-clean

A faster drop in replacement for bin/magento cache:clean with file watcher
BSD 3-Clause "New" or "Revised" License
531 stars 63 forks source link

Warden Support #82

Closed sprankhub closed 4 years ago

sprankhub commented 4 years ago

I currently try Warden and would love to use the cache clean tool with it. I would love to run it from my host machine and not the Docker container. This has the advantage that I can simply open the PhpStorm project and PhpStorm will run the file watcher automatically. I read https://github.com/mage2tv/magento-cache-clean/blob/master/doc/docker-and-vm.md to get started. And I think it might be a good idea to run the generate-cache-clean-config.php script and check if this helps. However, I do not think that the following error would really be fixed with it. Here is the full output:

> vendor/bin/cache-clean.js -vv
Release 1.0.31 sponsored by https://www.mage2.tv

Magento dir /var/www/shop
16:34:55 Flushing all caches
16:34:55 Using :default cache_backend
Reading app config by shelling out to php
16:34:55 Cache storage  {:id_prefix 69d_, :backend Magento\Framework\Cache\Backend\Redis, :backend_options {:server redis, :database 0, :port 6379, :password , :compress_data 1, :compression_lib }}
16:34:55 Flushing redis db 0
16:34:55 Using :page_cache cache backend
Reading app config by shelling out to php
16:34:55 Cache storage  {:id_prefix 69d_, :backend Magento\Framework\Cache\Backend\Redis, :backend_options {:server redis, :database 1, :port 6379, :password , :compress_data 0, :compression_lib }}
16:34:55 Flushing redis db 1
Reading app config by shelling out to php
16:34:55 Varnish request: #js {:protocol http:, :hostname varnish, :port 80, :method PURGE, :path /, :headers #js {:X-Magento-Tags-Pattern .*}, :timeout 10000}
16:34:55 Using :default cache_backend
Reading app config by shelling out to php
16:34:56 Cache storage  {:id_prefix 375_, :backend Cm_Cache_Backend_File, :cache_dir /var/www/shop/dev/tests/integration/tmp/sandbox-0-21740e90fd6f9504da58f92df464adc345e7347b1807e791e6e14362f40fbdf7/var/cache}
16:34:56 Cleaning dir /var/www/shop/dev/tests/integration/tmp/sandbox-0-21740e90fd6f9504da58f92df464adc345e7347b1807e791e6e14362f40fbdf7/var/cache/
16:34:56 Using :page_cache cache backend
Reading app config by shelling out to php
16:34:56 Cache storage  {:id_prefix 375_, :backend Cm_Cache_Backend_File, :cache_dir /var/www/shop/dev/tests/integration/tmp/sandbox-0-21740e90fd6f9504da58f92df464adc345e7347b1807e791e6e14362f40fbdf7/var/page_cache}
16:34:56 Cleaning dir /var/www/shop/dev/tests/integration/tmp/sandbox-0-21740e90fd6f9504da58f92df464adc345e7347b1807e791e6e14362f40fbdf7/var/page_cache/
Reading app config by shelling out to php
16:34:56 Varnish request: #js {:protocol http:, :hostname varnish, :port 80, :method PURGE, :path /, :headers #js {:X-Magento-Tags-Pattern .*}, :timeout 10000}
events.js:187
      throw er; // Unhandled 'error' event
      ^

Error: Redis connection to redis:6379 failed - getaddrinfo ENOTFOUND redis
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
Emitted 'error' event on RedisClient instance at:
    at RedisClient.on_error (/var/www/shop/vendor/mage2tv/magento-cache-clean/node_modules/redis/index.js:406:14)
    at Socket.<anonymous> (/var/www/shop/vendor/mage2tv/magento-cache-clean/node_modules/redis/index.js:279:14)
    at Socket.emit (events.js:210:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'redis'
}

Do you understand what is happening here, @Vinai? Is this something, which could be handled?

sprankhub commented 4 years ago

Interestingly enough, having the config file var/cache-clean-config.json in place does fix this specific error. However, maybe this can be handled more gracefully then?

sprankhub commented 4 years ago

Okay not really - I could not reproduce the issue at the same place after generating the config file, but changing something in another file brought up the same error again.

Vinai commented 4 years ago

I don't think this is possible with the out-of-the-box env.php, because the in-docker container DNS names don't resolve on the host machine, even if the ports of the services are exposed.

It would be cool to be able to run the watcher on the host machine, but I don't think that is possible by making changes to the cache-clean.js tool. If the warden team somehow is able to create resolvable routes to the services from the host machine, and use those in the env.php file, then running the watcher locally should "just work". For now, I think I'll have to close this as a wont-fix - sorry :'-(

Maybe you have time to create a PR to warden, or maybe open an issue at https://github.com/davidalger/warden/ for this?

jantzenw commented 3 years ago

For future readers, it might be possible to run warden env exec php-fpm vendor/bin/cache-clean.js -w from the host machine instead of vendor/bin/cache-clean.js -w