Created
July 30, 2020 13:03
-
-
Save ngaranko/d22eb183990c7a1187fb6732acb75881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class maybe_delay(object): | |
""" | |
Will delay jobs if RQ is enabled. | |
""" | |
def __init__(self, func, call_directly=None): | |
self.func = func | |
self.call_directly = call_directly | |
def delay(self, *args, **kwargs): | |
if settings.RQ_DISABLED: | |
return self.func(*args, **kwargs) | |
if self.call_directly is not None and self.call_directly: | |
return self.func(*args, **kwargs) | |
return self.func.delay(*args, **kwargs) | |
def __call__(self, *args, **kwargs): | |
# Explicitly called functions are not delayed. | |
return self.func(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment