Skip to content

Commit

Permalink
Allow users to override the TaskWrapper implementation.
Browse files Browse the repository at this point in the history
Refs #783
  • Loading branch information
coleifer committed Jan 9, 2024
1 parent 3e7bdf2 commit 383331e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions huey/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def __init__(self, name='huey', results=True, store_none=False, utc=True,
self.storage_class = storage_class
self.storage = self.create_storage()

# Allow overriding the default TaskWrapper implementation.
self.task_wrapper_class = self.get_task_wrapper_class()

self._locks = set()
self._pre_execute = OrderedDict()
self._post_execute = OrderedDict()
Expand All @@ -126,6 +129,9 @@ def __init__(self, name='huey', results=True, store_none=False, utc=True,
self._signal = S.Signal()
self._tasks_in_flight = set()

def get_task_wrapper_class(self):
return TaskWrapper

def create_storage(self):
# When using immediate mode, the default behavior is to use an
# in-memory broker rather than a live one like Redis or Sqlite, however
Expand Down Expand Up @@ -166,6 +172,7 @@ def create_consumer(self, **options):

def task(self, retries=0, retry_delay=0, priority=None, context=False,
name=None, expires=None, **kwargs):
TaskWrapper = self.task_wrapper_class
def decorator(func):
return TaskWrapper(
self,
Expand All @@ -182,6 +189,7 @@ def decorator(func):
def periodic_task(self, validate_datetime, retries=0, retry_delay=0,
priority=None, context=False, name=None, expires=None,
**kwargs):
TaskWrapper = self.task_wrapper_class
def decorator(func):
def method_validate(self, timestamp):
return validate_datetime(timestamp)
Expand Down

0 comments on commit 383331e

Please sign in to comment.