steinitzu / celery-singleton

Seamlessly prevent duplicate executions of celery tasks
MIT License
237 stars 36 forks source link

unique_on improvements #39

Closed dmartin closed 3 years ago

dmartin commented 3 years ago

Makes two changes to unique_on behavior.

  1. Allows specifying unique_on=[] to consider task name only for uniqueness:

    @app.task(base=Singleton, unique_on=[])
    def do_something(username, otherarg=None):
        time.sleep(5)
    
    # Previous behavior: equivalent to unique_on=None ([] parsed as falsey value)
    # New behavior: only the task name "do_something" is used to generate lock
  2. Allows tasks with default arguments in unique_on to be called without explicitly specifying values:

    @app.task(base=Singleton, unique_on=["otherarg"])
    def do_something(username, otherarg=None):
        time.sleep(5)
    otherarg.delay(sample)
    
    # Previous behavior: exception raised in generate_lock due to missing key in BoundArguments
    # New behavior: default arguments can be omitted when calling task

Resolves #15 Resolves #23

dmartin commented 3 years ago

Btw, I don't think the test_singleton.py::TestUniqueOn::test__unique_on_pos_arg__lock_on_unique_args_only failures are related, I ocassionally get the same failure (call_count == 3) even when running the tests locally against master.

steinitzu commented 3 years ago

Thank you! Looks good.

Yes these tests are a little flaky/timing sensitive. So no worries.

ento commented 2 years ago

@steinitzu If you can find the time, it'd be copacetic to have a new PyPI release that includes this fix.