When I run the batch file to enable Celery:
python.exe -m celery -A tasks worker.celery -P eventlet -f celery.logs -l info
An error occurs:
Traceback (most recent call last):
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\runpy.py", line 85, in _run_code exec(code, run_globals)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery__main__.py", line 18, in main()
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery__main__.py", line 14, in main _main()
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery\bin\celery.py", line 326, in main cmd.execute_from_commandline(argv)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery\bin\celery.py", line 488, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery\bin\base.py", line 279, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery\bin\base.py", line 481, in setup_app_from_commandline
self.app = self.find_app(app)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery\bin\base.py", line 503, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery\app\utils.py", line 355, in find_app
sym = symbol_by_name(app, imp=imp)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery\bin\base.py", line 506, in symbol_by_name
return imports.symbol_by_name(name, imp=imp)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\kombu\utils\imports.py", line 56, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\site-packages\celery\utils\imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "C:\Users\Chernov.a\Desktop\Projects\Roscosmos\Python36-32\lib\importlib__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tasks'
I tried to add this path to the sys.path, change the virtual environment, but nothing helped.
The code itself tasks.py
import requests
from requests.auth import HTTPBasicAuth
from celery import Celery
celery_app = Celery('nsi', broker='amqp://guest@localhost//')
@celery_app.task(
name='sendToNsi',
default_retry_delay = 4 *(60 * 60),
max_retries = 1000,
autoretry_for=(Exception,))
def sendToNsi(NSI_url,answer):
s=requests.Session()
post_request = s.post(NSI_url, data=answer,auth=HTTPBasicAuth('__', '___'))
post_request.raise_for_status()
Project structure
───webNSI
│ 1.py
│ config.py
│ config1.py
│ journal.log
│ Message.xsd
│ Schemas.py
│ test2.py
│ views - Copy.py
│ views.py
│ views2.py
│ __init__.py
│
├───model
│ │ Answers.py
│ │ DBOperation.py
│ │ XmlHandler.py
│ │ __init__.py
│ │
│ ├───MQ
│ │ │ celery.logs
│ │ │ CeleryMQ_Task.xml
│ │ │ celery_worker.bat
│ │ │ tasks.py
│ │ │ __init__.py
│ │ │
│ │ └───__pycache__
│ │ tasks.cpython-36.pyc
│ │ __init__.cpython-36.pyc
│ │
│ └───__pycache__
│ Answers.cpython-36.pyc
│ DBOperation.cpython-36.pyc
│ XmlHandler.cpython-36.pyc
│ __init__.cpython-36.pyc
│
└───__pycache__
config.cpython-36.pyc
Schemas.cpython-36.pyc
views.cpython-36.pyc
__init__.cpython-36.pyc
__init__.cpython-37.pyc
───__pycache__
runserver.cpython-36.pyc
How I can solve this problem?