Skip to content

Create services for the classification jobs - #176

Merged
stephen-riggs merged 22 commits into
mainfrom
class-services
Jul 15, 2025
Merged

Create services for the classification jobs#176
stephen-riggs merged 22 commits into
mainfrom
class-services

Conversation

@stephen-riggs

@stephen-riggs stephen-riggs commented Jul 10, 2025

Copy link
Copy Markdown
Contributor

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.

@codecov

codecov Bot commented Jul 10, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 82.32143% with 99 lines in your changes missing coverage. Please review.

Project coverage is 81.42%. Comparing base (f1f52be) to head (39ac10f).
Report is 3 commits behind head on main.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stephen-riggs stephen-riggs self-assigned this Jul 14, 2025
@stephen-riggs
stephen-riggs marked this pull request as ready for review July 14, 2025 11:26
Comment thread src/cryoemservices/services/class2d.py
Comment thread src/cryoemservices/services/common_service.py Outdated
Comment on lines +31 to +61
"""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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread src/cryoemservices/wrappers/class2d_wrapper.py
Comment thread src/cryoemservices/wrappers/class3d_wrapper.py Outdated
Comment thread src/cryoemservices/wrappers/class3d_wrapper.py Outdated
Comment thread src/cryoemservices/wrappers/class2d_wrapper.py Outdated
Comment thread src/cryoemservices/wrappers/class3d_wrapper.py Outdated
Comment thread src/cryoemservices/wrappers/refine3d_wrapper.py Outdated
Comment thread src/cryoemservices/wrappers/refine3d_wrapper.py Outdated

@tieneupin tieneupin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@stephen-riggs
stephen-riggs merged commit 5275905 into main Jul 15, 2025
12 checks passed
@stephen-riggs
stephen-riggs deleted the class-services branch July 15, 2025 14:01
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.

2 participants