I'm trying to use python huey (https://github.com/coleifer/huey/blob/master/huey/api.py) to allow usage of a task queue with flask.
Starting with the file app.tasking.tasks:
from . import my_huey
from app.main.cl import dummy_create_cl_listing, create_cl_listing
from app.main.mobiletest import some_long_calculation,create_chromedriver
create_cl_listing_task = my_huey.task()(create_cl_listing)
some_long_calculation_task = my_huey.task()(some_long_calculation)
@my_huey.task()
def dummy_create_task(messages):
time.sleep(5)
print('continuing..')
time.sleep(25)
return 'fin'
If I run :
$ python ...huey_consumer.exe run_huey.huey where run_huey.py (which is a file in the project root directory) contains:
from app.tasking.tasks import my_huey as huey
if __name__ == '__main__':
pass
I see:
[2018-08-22 14:10:58,587] INFO:huey.consumer:MainThread:The following commands are available:
+ queue_task_create_cl_listing
+ queue_task_some_long_calculation
+ queue_task_dummy_create_task
showing that the tasks are available. However, if I am unable to import the functions which I have turned into tasks into the app.main.views file so that I can call it via a view function. for example if I add:
from app.tasking.tasks import some_long_calculation_task
to the main.views file:
[91mError importing run_huey.huey?[0m
Traceback (most recent call last):
File "...\lib\site-packages\huey\bin\huey_consumer.py", line 18, in load_huey
return load_class(path)
File "...\lib\site-packages\huey\utils.py", line 46, in load_class
__import__(path)
ModuleNotFoundError: No module named 'run_huey'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "...\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "...\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "...\Scripts\huey_consumer.exe\__main__.py", line 9, in <module>
File "...\lib\site-packages\huey\bin\huey_consumer.py", line 43, in consumer_main
huey_instance = load_huey(args[0])
File "...\lib\site-packages\huey\bin\huey_consumer.py", line 23, in load_huey
return load_huey(path)
File "...\lib\site-packages\huey\bin\huey_consumer.py", line 18, in load_huey
return load_class(path)
File "...\lib\site-packages\huey\utils.py", line 46, in load_class
__import__(path)
File "...\run_huey.py", line 12, in <module>
from app.tasking.tasks import my_huey as huey
File "...\app\tasking\tasks.py", line 3, in <module>
from app.main.cl import dummy_create_cl_listing, create_cl_listing
File "...\app\main\__init__.py", line 1, in <module>
from app.main import errors # noqa
File "...\app\main\errors.py", line 3, in <module>
from app.main.views import main
File "...\app\main\views.py", line 14, in <module>
from app.tasking.tasks import some_long_calculation_task
ImportError: cannot import name 'some_long_calculation_task'
How can I fix this?