Skip to content

Commit

Permalink
Allow task pipelines to run when always_eager=True.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed May 17, 2018
1 parent b53aade commit 2c465dc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion huey/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,21 @@ def emit(self, message):
# critical component.
pass

def _execute_always_eager(self, task):
accum = []
while task is not None:
result = task.execute()
accum.append(result)
if task.on_complete:
task = task.on_complete
task.extend_data(result)
else:
task = None
return accum[0] if len(accum) == 1 else accum

def enqueue(self, task):
if self.always_eager:
return task.execute()
return self._execute_always_eager(task)

self._enqueue(self.registry.get_message_for_task(task))
if not self.result_store:
Expand Down
17 changes: 17 additions & 0 deletions huey/tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,3 +644,20 @@ def test_flush_locks(self):

self.assertEqual(flushed, set(['lock1', 'lock2']))
self.assertEqual(huey.flush_locks(), set())


eager_huey = RedisHuey(blocking=False, always_eager=True)

@eager_huey.task()
def add(a, b):
return a + b


class TestAlwaysEager(BaseQueueTestCase):
def test_always_eager(self):
self.assertEqual(add(1, 3), 4)

# Test pipelining.
pipe = add.s(1, 2).then(add, 3).then(add, 4).then(add, 5)
result = eager_huey.enqueue(pipe)
self.assertEqual(result, [3, 6, 10, 15])

0 comments on commit 2c465dc

Please sign in to comment.