Skip to content

Support graceful at config.ONCE level #144

Open
@gigatesseract

Description

I am writing a django app with celery once and if a task is already queued, I dont want to raise an exception, so I want to add graceful option to the task.

Now, I want that config for all the tasks that I have written, so that I dont have to specify that config evertytime.

From the code,

once_graceful = once_options.get(
            'graceful', self.once.get('graceful', False))

So I can override this in the following places -
* At the apply_async call level
* When I am defining the once property for my task

The problems I think will arise with respect to maintenance -
* I have to do that for all the tasks I have coded
* Since I will have to override the entire once object, in the future, if any defaults are added by the package maintainers, it will be overwritten.

I want to override it at the config.ONCE level so that I can just add it to the app.

I was looking at timeout, and I see something like this-

        once_timeout = once_options.get(
            'timeout', self.once.get('timeout', self.default_timeout))


    @property
    def once_config(self):
        return self.config.ONCE

    @property
    def default_timeout(self):
        return self.once_config['settings'].get('default_timeout', 60 * 60)

So, what I want to do is something like

in the app, have a property for graceful

    @property
    def graceful(self):
        return self.once_config['settings'].get('graceful', False)

Then overwrite it during apply_Async from the property as default. This will help anyone override the graceful config at app level

Let me know yuour thoughts

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions