Skip to content

Conversation

@jmsmkn
Copy link
Contributor

@jmsmkn jmsmkn commented Nov 17, 2025

This PR implements a new signal, process_picture_done, which is emitted when the task completes. It adds a new kwarg to PictureProcessor instances, field, which is a string so that it can be serialized in Celery and contains the model name, app label and field name. This, combined with the file name, allows the user to find which instance(s) this processing task corresponds to, so that they could then take action, e.g. by setting a processing done field in the database.

Any feedback welcome!

See #160

Copy link
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

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

Cool, that's an interesting suggestion. I wonder if we can take this a step further and have a persistent "processed" state on the model.

Maybe similar to the dimension fields…
I want to make sure that this package is pretty convenient by default and then allows you to grow and adapt behavior to your needs.

This doesn't need to be implemented into the library necessarily, but we should at least add a cookbook on how to use the signal for this use case.

file_name: str,
new: list[tuple[str, list, dict]] | None = None,
old: list[tuple[str, list, dict]] | None = None,
field: str = "",
Copy link
Owner

Choose a reason for hiding this comment

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

All that matters for async task runners, is that the signature is JSON-serializable.
You don't need to concatenate the strings; just pass a triple:

Suggested change
field: str = "",
sender: tuple[str, str, str],

You can drop the default, since this will be required. And I'd prefer to keep the naming somewhat consistent. Thus, this would be the sender (sending the task).

Copy link
Contributor Author

@jmsmkn jmsmkn Nov 28, 2025

Choose a reason for hiding this comment

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

Making it required means that it needs to be placed before new and old, which is more of a breaking change than making it optional. It does make upgrading more difficult as existing celery tasks without the kwarg being set could be on users queues, so they would end up being rejected.

Now that we're sending along the field as the sender the storage could also be dropped as that could be found in the task from the field, but that would cause issues on upgrading again due to it being set as a kwarg to the celery tasks.

Having sender as optional would allow a more graceful upgrade path, they could then be made required in a further major release. Same with making storage optional for now before removal in a further major release.

@codingjoe codingjoe added the enhancement New feature or request label Nov 28, 2025
@codingjoe codingjoe changed the title Add process_picture_done signal Add picture_processed signal Nov 28, 2025
@codingjoe codingjoe changed the title Add picture_processed signal Resolve #160 -- Add picture_processed signal Nov 28, 2025
@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.40%. Comparing base (e9b6583) to head (4077289).

Additional details and impacted files
@@             Coverage Diff             @@
##              main     #231      +/-   ##
===========================================
- Coverage   100.00%   99.40%   -0.60%     
===========================================
  Files           13       14       +1     
  Lines          495      505      +10     
===========================================
+ Hits           495      502       +7     
- Misses           0        3       +3     
Flag Coverage Δ
celery 85.34% <85.71%> (+0.29%) ⬆️
cleanup 88.11% <78.57%> (-0.37%) ⬇️
dj4.2 88.11% <78.57%> (-0.37%) ⬇️
dj5.1 88.11% <78.57%> (-0.37%) ⬇️
django-rq 85.34% <85.71%> (+0.29%) ⬆️
dramatiq 85.34% <85.71%> (+0.29%) ⬆️
drf 95.84% <78.57%> (-0.53%) ⬇️
macos-latest 88.31% <78.57%> (-0.38%) ⬇️
py3.10 88.11% <78.57%> (-0.37%) ⬇️
py3.11 88.11% <78.57%> (-0.37%) ⬇️
py3.12 88.11% <78.57%> (-0.37%) ⬇️
py3.13 88.11% <78.57%> (-0.37%) ⬇️
py3.14 88.11% <78.57%> (-0.37%) ⬇️
ubuntu-latest 88.11% <78.57%> (-0.37%) ⬇️
windows-latest 81.05% <72.72%> (-0.54%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jmsmkn jmsmkn force-pushed the process_picture_signal branch from e54b332 to ed11b97 Compare November 28, 2025 17:43
@jmsmkn jmsmkn removed their assignment Nov 28, 2025
Cleanup sets instance to a FakeInstance, so needed to find the model through another path.
@jmsmkn
Copy link
Contributor Author

jmsmkn commented Nov 29, 2025

Cool, that's an interesting suggestion. I wonder if we can take this a step further and have a persistent "processed" state on the model.

Maybe similar to the dimension fields… I want to make sure that this package is pretty convenient by default and then allows you to grow and adapt behavior to your needs.

This doesn't need to be implemented into the library necessarily, but we should at least add a cookbook on how to use the signal for this use case.

Thanks for the feedback, I think this is ready for another look.

If this is the correct approach I wonder if a second signal could be useful - processing_scheduled or picture_changed when the task is scheduled? That way the picture_processed attribute can be reset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants