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

Refactor start of processing a supp. billing batch #233

Merged
merged 2 commits into from
May 18, 2023

Conversation

Cruikshanks
Copy link
Member

https://eaflood.atlassian.net/browse/WATER-3977
https://eaflood.atlassian.net/browse/WATER-3984

Both to help resolve some issues found when cleaning up our existing process billing batch service and to support changes need for handling multi-year bill runs we need to make some changes.

The key one is ProcessBillingBatchService is no longer appropriate because it is actually focused on processing a single billing period. So, we renamed it to ProcessBillingPeriodService and have created a new ProcessBillingBatchService responsible for orchestrating the whole process.

As the primary service now, we've updated the controller to call it instead of InitiateBillingBatchService. This resulted in us needing to make further changes in it and the services it uses.

Along the way we spotted opportunities to clean up some other things; passing in params only to find they are hard coded elsewhere, or having params named differently to how they are used within a service.

https://eaflood.atlassian.net/browse/WATER-3977
https://eaflood.atlassian.net/browse/WATER-3984

Both to help resolve some issues found when cleaning up our existing process billing batch service and to support changes need for handling multi-year bill runs we need to make some changes.

The key one is `ProcessBillingBatchService` is no longer appropriate because it is actually focused on process a single billing period. So, we renamed it to `ProcessBillingPeriodService` and have created a new `ProcessBillingBatchService` responsible for orchestrating the _whole_ process.

As the primary service now, we've updated the controller to call it instead of `InitiateBillingBatchService`. This resulted in use needing to make further changes in it and the services it uses.

Along the way we spotted opportunities to clean up some other things; passing in params only to find they are hard coded elsewhere, or having params named differently to how they are used within a service.
@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label May 18, 2023
@Cruikshanks Cruikshanks self-assigned this May 18, 2023
@Cruikshanks Cruikshanks requested review from Jozzey and StuAA78 May 18, 2023 11:33
@Cruikshanks Cruikshanks marked this pull request as ready for review May 18, 2023 11:34
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a couple of minor issues

@Cruikshanks Cruikshanks merged commit 3c7bee7 into main May 18, 2023
@Cruikshanks Cruikshanks deleted the refactor-process-billing-batch branch May 18, 2023 12:43
Cruikshanks added a commit that referenced this pull request May 22, 2023
https://eaflood.atlassian.net/browse/WATER-3977
https://eaflood.atlassian.net/browse/WATER-3984

This is a follow on from [Refactor start of processing a supp. billing batch](#233). In there we needed to refactor the `ProcessBillingBatchService` to not mix processing a given billing period and the overall billing batch. So, we created `ProcessBillingPeriodService` and split the functionality between the 2.

But we parked writing any unit tests for our new `ProcessBillingBatchService` till this PR, else the change would have been massive. Only we hit an issue when we started writing them.

`ProcessBillingBatchService` in its new form was determining the billing periods, initiating the billing batch record, and generating a response back to the client all whilst kicking off the process for each billing period and handling any errors thrown. It was also responsible for finalising the bill run.

A bit much! The final issue was that background processing was not `awaited`. This made it a nightmare to try and test all this behaviour.

We realised we needed to get the 'processing' bit in its own service if only to make it testable. So, this change adds a new `NewBillingBatchService` (yes - we really need to sit down and firm up our naming conventions!)

_This_ is now what is called when kicking off a new billing batch. It deals with determining the billing periods, initiating the billing batch, and generating the response for the client. Essentially, it manages everything to do with a new bill run. It also kicks off `ProcessBillingBatchService` in the background, which is now solely focused on processing a billing batch; generating the data, handling errors, updating the billing batch status, and finalising it.

With this in place, it meant we could also write some unit tests!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants