shiftgig / celery-unique

Python factory for limiting Celery tasks by configuration
Apache License 2.0
7 stars 2 forks source link
apache celery celery-tasks deduplication unique-constraints

celery-unique

Travis CI build status Codecov coverage report Latest PyPI release License

Adds argument-based unique constraints to Celery tasks

Overview

Configuring unique constraints on Celery requires the following:

Usage:

In the above example, three Celery tasks were created. However, in processing our third call, the handling provided by celery-unique found that there was already a pending result for add_first_and_last() with a unique key of "1 with 3" (generated by the lambda). So what happened? The first task was automatically revoked, and the most recent task was then sent along to be handled by Celery.

This is especially useful for creating time-based tasks like emails. If we create a task to re-engage users via email 30 days after the last time we saw them, we could create a task with an ETA of 30 days from the current time each time they visited. If we didn't have celery-unique in this scenario and a user made visits on Monday, Tuesday, and Wednesday, then they would get an email 30 days after Monday, 30 days after Tuesday, and 30 days after Wednesday. With celery-unique (and a proper task configuration, of course), the only email sent would be 30 days after Wednesday. Huzzah!

Hacking

Versions are handled by setuptools-scm. To release a new version, tag the relevant commit, and the push it to GitHub. Travis will push the package to PyPI automatically.

Licence

Copyright 2015-2017, Shiftgig Inc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.