Create services for the classification jobs - #176
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #176 +/- ##
==========================================
+ Coverage 80.42% 81.42% +1.00%
==========================================
Files 58 61 +3
Lines 7197 7354 +157
Branches 1017 1033 +16
==========================================
+ Hits 5788 5988 +200
+ Misses 945 910 -35
+ Partials 464 456 -8 🚀 New features to boost your workflow:
|
| """Main function which interprets and processes received messages""" | ||
| if not rw: | ||
| self.log.info("Received a simple message") | ||
| if not isinstance(message, dict): | ||
| self.log.error("Rejected invalid simple message") | ||
| self._transport.nack(header) | ||
| return | ||
|
|
||
| # Create a wrapper-like object that can be passed to functions | ||
| # as if a recipe wrapper was present. | ||
| rw = MockRW(self._transport) | ||
| rw.recipe_step = {"parameters": message} | ||
|
|
||
| try: | ||
| if isinstance(message, dict): | ||
| refine_params = RefineParameters( | ||
| **{**rw.recipe_step.get("parameters", {}), **message} | ||
| ) | ||
| else: | ||
| refine_params = RefineParameters( | ||
| **{**rw.recipe_step.get("parameters", {})} | ||
| ) | ||
| message = {} | ||
| except (ValidationError, TypeError) as e: | ||
| self.log.warning( | ||
| f"Refine3D parameter validation failed for message: {message} " | ||
| f"and recipe parameters: {rw.recipe_step.get('parameters', {})} " | ||
| f"with exception: {e}" | ||
| ) | ||
| rw.transport.nack(header) | ||
| return |
There was a problem hiding this comment.
I wonder if it's worth embedding this recipe wrapper handling logic with the CommonService class instead, as based on my experience writing the CLEM services and reviewing this one, it looks like it's repeated every time.
tieneupin
left a comment
There was a problem hiding this comment.
Thanks for explaining some of the intricacies regarding why certain files had to be created and deleted. Some suggestions for optimisation, but other than that, I couldn't spot anything wrong. I'm assuming you've run these services on real data by this point.
Adds the option to run classification jobs as services.
These can take much longer than the rabbitmq timeout of 30 minutes, so rather than hold the message they acknowledge as soon as the process starts, then resend any failed messages to the queue.
To replicate the nacking behaviour on failure, they record the number of reinjections and nack after 5.
The diff for this PR is very large as the wrapper code had to be broken into separate functions, but the amount of new code is relatively small.