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
Convert VirusScanner class into stateless service #372
Merged
floehopper
merged 10 commits into
master
from
convert-virus-scanner-into-stateless-service
Jan 3, 2018
Merged
Convert VirusScanner class into stateless service #372
floehopper
merged 10 commits into
master
from
convert-virus-scanner-into-stateless-service
Jan 3, 2018
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The VirusScanner class is only ever instantiated in the VirusScanWorker and in that case, the #clean method is only called once on that instance. Thus this optimisation is only ever exercised in the VirusScanner spec example which I have removed. My motivation for making this change is that I want to convert VirusScanner into a stateless service to bring it into line with S3Storage and services in other GOV.UK apps. This change is a step in that direction.
The #clean method is no longer adding much value and doing this will make it easier to convert this class into a stateless service.
This is a further step towards converting this class into a stateless service.
Previously this method was returning `false` if a virus was detected. I'm converting this class into a stateless service and so I want to avoid having to store `virus_info` when a virus is detected. We can do this by raising the exception and handling it in the VirusScanWorker. Handling the exception in the worker is important, because we want to avoid triggering the Sidekiq retry mechanism. Note that the `virus_info` string is now passed as the exception message and since we send the original exception to GovukError.notify, there's no longer any need to include it in the `extra` Hash.
By removing this last remaining state variable, the class is now a stateless service.
Now that we are explicitly handling VirusScanner::InfectedFile exceptions in VirusScanWorker#perform, I think this comment is less useful and just clutters up the code.
Extract common code into `before` & `let` blocks and use `context` blocks to make the appriopriate changes to the context for each example. This also has the benefit of removing some long lines. I've also replaced the `status` double with an instance double which is more likely to catch problems.
Extract common code into `before` & `let` blocks and use `context` blocks to make the appriopriate changes to the context for each example. This also has the benefit of removing some long lines. I've also replaced the `scanner` double with an instance double which is more likely to catch problems.
floehopper
force-pushed
the
convert-virus-scanner-into-stateless-service
branch
from
December 29, 2017 15:52
674e553
to
c801627
Compare
Now that the VirusScanner class is a stateless service, we can include it in the standard Services module to bring this app more into line with other GOV.UK apps.
floehopper
force-pushed
the
convert-virus-scanner-into-stateless-service
branch
from
December 29, 2017 16:20
c801627
to
03a756c
Compare
chrislo
approved these changes
Jan 3, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think this simplifies the code, makes it easier to test and bring this app more into line with other GOV.UK apps.