Skip to content
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
merged 10 commits into from Jan 3, 2018

Conversation

floehopper
Copy link
Contributor

I think this simplifies the code, makes it easier to test and bring this app more into line with other GOV.UK apps.

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 floehopper force-pushed the convert-virus-scanner-into-stateless-service branch from 674e553 to c801627 Compare December 29, 2017 15:52
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 floehopper force-pushed the convert-virus-scanner-into-stateless-service branch from c801627 to 03a756c Compare December 29, 2017 16:20
@chrislo chrislo self-assigned this Jan 3, 2018
@floehopper floehopper merged commit 0bfa0c8 into master Jan 3, 2018
@floehopper floehopper deleted the convert-virus-scanner-into-stateless-service branch January 3, 2018 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants