-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve image caches in background. Using message queue. #919
Conversation
I like the idea of producing images asynchronously. - In fact I would like to see it added. The container makes it a pretty easy to just plug it in. +1 from my side. |
I love the intention of this PR, but I hate adding more "optional dependencies" that require "manual configuration". Is there a library, instead of a bundle, that we can use, so we're only adding an "optional dependency" and not also "required manual configuration" needed to set up the extra bundle? This isn't a deal breaker for me; just interested if there are any zero-configuration options. |
Yes there is the library and the bundle does not do much, it is only a glue layer over the library stuff. Everything could be used in plain php, even consumers though it would require a bit more work to setup
There is no much we can do with it. Enqueue supports different transport (AMQP, Stomp, Redis, Amazon SQS) they all require different configuration options. It does not make much difference whether we use library or the bundle we still have to do that |
Fair enough; I'm onboard then. After some tests and docs are added (which, as you pointed out, you were waiting on to ensure you didn't waste your time) this looks like a fairly simple addition in terms of added code complexity, yet brings with it a very cool and much-requested functionality. It appears as though php-enqueue/enqueue-bundle is primarily maintained by yourself, so I would only want to ensure you intend to regularly update the bundle, especially as it applies to the upcoming Otherwise, his looks like an excellent addition @makasim. |
Wouldn't it make more sense for this pull request to be against the I know |
@robfrawley In general I dont mind merging it to 2.x though I tried to tweak travis script to install enqueue only on 5.6 or higher PHP versions and the tests marked skipped if no enqueue installed (the case for PHP 5.3). Also composer helps here a lot. It would not allow a developer to install enqueue on old PHP version preventing them from breaking things. |
|
||
$result = $processor->process($message, new NullContext()); | ||
|
||
$this->assertInstanceOf(Result::class, $result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If merged in 1.x
these need to be resolved FQCNs for merge into 1.x
but is fine if we merge into 2.x
.
|
||
$result = $processor->process($message, new NullContext()); | ||
|
||
$this->assertInstanceOf(Result::class, $result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If merged in
1.x
these need to be resolved FQCNs for merge into1.x
but is fine if we merge into2.x
.
|
||
$this->assertInternalType('array', $topics); | ||
$this->assertArrayHasKey(Topics::RESOLVE_ALL_CACHE, $topics); | ||
$this->assertEquals([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the short array syntaxes need to go, as well if you want to merge this against 1.x
. Not the case if you chose 2.x
instead.
public static function setUpBeforeClass() | ||
{ | ||
if (false == interface_exists('Enqueue\Psr\PsrProcessor')) { | ||
throw new \PHPUnit_Framework_SkippedTestError('The enqueue bundle is not installed. Skip optional tests'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the parent class to handle this versus throwing this exception yourself (this is also how we handle it in other test cases within this bundle):
if (false == interface_exists('Enqueue\Psr\PsrProcessor')) {
$this->markTestSkipped('The enqueue bundle is not installed. Skip optional tests');
}
Even though you are marking the test as skipped, the lower version PHP engines are still going to perform a compilation step on the test classes, so they need to run on PHP I don't have a strong preference one way or the other (between using |
b6811dd
to
1f9e643
Compare
1f9e643
to
c424a2c
Compare
c424a2c
to
fefad25
Compare
ea0ea7e
to
cf0cdbf
Compare
@robfrawley Ready for review. rebased and squashed. The doc and tests are there. Though I am not familiar with rst format it would be good if someone who knows it check the doc. |
cf0cdbf
to
ed7810b
Compare
That's used in enqueue:topics command. It shows available topics and their descriptions, and what is subscribed on the topic.
@@ -55,6 +57,7 @@ before_install: | |||
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION:0:3}" != "5.3" ]; then composer require --no-update --dev league/flysystem:~1.0; fi; | |||
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION:0:1}" != "7" ]; then yes "" | pecl -q install -f mongo; composer require --no-update --dev doctrine/mongodb-odm:~1.0; fi; | |||
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION:0:1}" == "7" ]; then yes "" | pecl -q install -f mongodb; travis_retry composer require --dev alcaeus/mongo-php-adapter:~1.0; composer require --no-update --dev doctrine/mongodb-odm:~1.0; fi | |||
- if [ "$WITH_ENQUEUE" = true ] ; then composer require --no-update --dev enqueue/enqueue-bundle:^0.3.6; fi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not enable this test globally for all supported PHP versions? Or at least all PHP 7.x runs? I think this would be a better approach to ensure no incompatibilities are introduced across Symfony versions. We already have some Symfony 2.32, 2.8
, 3.2
and 3.3
specific features or toggled usages.
All PHP 5.6
and PHP 7.x
Runs
if [ "${TRAVIS_PHP_VERSION:0:3}" == "5.6" ] || [ "${TRAVIS_PHP_VERSION:0:1}" == "7" ]; then [...] fi
All PHP 7.x
Runs
if [ "${TRAVIS_PHP_VERSION:0:1}" == "7" ]; then [...] fi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dependency is optional therefore I dont want it to be tested all the time.
What if something goes wrong when enqueue is not installed and we do not notice it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not only PHP version has to be taken into account but the version of Symfony as well. EnqueueBundle requires 2.8|3.0.
@@ -158,6 +158,7 @@ public function getConfigTreeBuilder() | |||
->end() | |||
->end() | |||
->end() | |||
->booleanNode('enqueue')->defaultFalse()->info('Enables integration with enqueue if set true. Allows resolve image caches in background by sending messages to MQ.')->end() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we spread this across lines?
->booleanNode('enqueue')
->defaultFalse()
->info('Enables integration with enqueue if set true. Allows resolve image caches in background by sending messages to MQ.')
->end()
{ | ||
public static function setUpBeforeClass() | ||
{ | ||
if (false == getenv('WITH_ENQUEUE')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I'd prefer this testing wasn't based on an environment variable but globally run if the required bundle exists. (Aside from the fact that no one contributing code is going to set this when locally testing, using class_exists
is a convention used regularly throughout this code base)
@makasim Have you built the RST documentation locally and ensured it's formatted as expected and without any compilation notices/warning/errors? It looks good to me on the first pass, but I always build the docs before pushing changes, myself. Aside from my previous comments, though, this looks great! |
@robfrawley No I haven't built it. Is there a doc on how to do it? |
The docs look correct to me and if there are warnings/notices/errors, you'll see them here: https://symfony.com/doc/build_errors Building the docs locally requires following these steps:
|
@makasim There are some additional steps you need to take to build the docs; to do a complete build that won't throw any notices, warning, or errors (unless it is supposed to) follow: https://github.com/liip/LiipImagineBundle/wiki/Building-RST-Documentation |
@robfrawley I tried to build doc as it is described here https://github.com/liip/LiipImagineBundle/wiki/Building-RST-Documentation It builds symfony docs and there are any errors and warnings but it ignores liip-imagine-bundle Here's the container I used: https://github.com/makasim/symfony-doc-builder I am sure I am missing something small. Could you please help? |
The third build step symlinks the So in the case of the instructions, given the following directory paths
The third build step
pointing to
You should be able to quite literally copy the steps from the wiki and end up with a valid result. |
There is no that step in the README.md but I did perform it. Here's what I have in docs folder (cleaned up output a bit):
|
This seems to work very well for me and enables browsing the generated source using Nginx by extending the
Build our Dockerfile and run the generated image:
And then load it up in your browser of choice (in this case Chrome):
|
@makasim Having built it, I can confirm your page isn't compiled because you aren't referencing it anywhere. You may want to add it to the |
@robfrawley symlink did not work for me (there were rst files in the container) so I copied them. Everything went fine (there was not any warnings not errors). I had to add my doc to index.rst. The doc is ok! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Merging then... |
@makasim Can you take a look at the |
@robfrawley looks good. |
The PR adds an ability to resolve image caches (apply filters and so on) in background process.
Right now if the new image is uploaded the cache images are not created. There is a controller for that and at first request the cache image is created and stored to the cache. The approach works but has some disadvantages.
This PR adds optional dependency on enqueue/enqueue-bundle and allows to process the images once they are uploaded.
Here's how you to use this:
You can run many instances to improve performance.
This is a RFC. Tests and doc will be added if the feature is accepted. There are other processors may be added as well, to delete cache or to cache a single filter.