gaiacoop / django-huey

A django integration for huey task queue that supports multi queue management
MIT License
67 stars 5 forks source link

Blocking tasks is not working #26

Closed mathijsfr closed 3 months ago

mathijsfr commented 3 months ago

I have a task that I run with django huey, but this task also runs multiple tasks from itself that I want to run in parallel. I also need to wait on the completion of all these tasks for my function to continue.

However, when I try to wait for the completion of a task, I get the error that task result is None.

I have a function wrapper to run tasks in parallel:

from django_huey import db_task
@db_task(queue='test_q')
def function_wrapper(func):
    try:
        result = func()
        return {'status': 'success', 'result': result}
    except Exception as e:
        return {'status': 'error', 'error': str(e)}

This is called from a function like so:

@db_task(queue='new_website')
def sync():
        product_info_tasks = [
            function_wrapper(sync_hello),
            function_wrapper(sync_hello2),
            function_wrapper(sync_hello3)
        ]

        results = []
        for task_result in product_info_tasks:
            print(task_result)
            print(task_result.pending())
            result = task_result.get(blocking=True)
            results.append(result)
            if result['status'] == 'error':
                print(f"Error in task: {result['error']}")

This gives me the following error:

Traceback (most recent call last):
  File "<>", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 2, in <module>
  File "<>", line 114, in sync
    print(task_result.pending())
AttributeError: 'NoneType' object has no attribute 'pending'