Y
Y
Yevgeni2018-07-26 16:13:34
Python
Yevgeni, 2018-07-26 16:13:34

Problem when running celery with Flask. What is the problem?

My flask app:

from flask import Flask
from celery import Celery


app = Flask(__name__)
app.debug = True
app.config['CELERY_BROKER_URL'] = 'mongodb://логин:пароль@ds243041.mlab.com:43041/flaskmongodb'
app.config['CELERY_RESULT_BACKEND'] = 'mongodb://логин:пароль@ds243041.mlab.com:43041/flaskmongodb'

celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config

@app.route('/run_Task')
def run_celery_task():
    my_task.delay()
    return 'Задача запущена'


@celery.task(name='app.my_task')
def my_task():
    return 'task completed'

if __name__ == '__main__':
    app.run()

In the console, I write
celery -A run_flask.celery worker --loglevel=info
And the output is an error:
spoiler

Process SpawnPoolWorker-4:
Traceback (most recent call last):
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\kombu\utils\objects.py", line 42, in __get__
return obj.__dict__[self.__name__]
KeyError: 'default_modules'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\kombu\utils\objects.py", line 42, in __get__
return obj.__dict__[self.__name__]
KeyError: 'data'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\billiard\process.py", line 327, in _bootstrap
self.run()
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\billiard\process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\billiard\pool.py", line 286, in __call__
self.after_fork()
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\billiard\pool.py", line 395, in after_fork
self.initializer(*self.initargs)
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\concurrency\prefork.py", line 55, in process_initializer
app.loader.init_worker()
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\loaders\base.py", line 114, in init_worker
self.import_default_modules()
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\loaders\base.py", line 109, in import_default_modules
return [self.import_task_module(m) for m in self.default_modules]
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\kombu\utils\objects.py", line 44, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\loaders\base.py", line 227, in default_modules
tuple(maybe_list(self.app.conf.imports)) +
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\utils\collections.py", line 126, in __getattr__
return self[k]
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\utils\collections.py", line 429, in __getitem__
return getitem(k)
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\utils\collections.py", line 278, in __getitem__
return mapping[_key]
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\collections\__init__.py", line 987, in __getitem__
if key in self.data:
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\kombu\utils\objects.py", line 44, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\app\base.py", line 141, in data
return self.callback()
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\app\base.py", line 924, in _finalize_pending_conf
conf = self._conf = self._load_config()
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\app\base.py", line 938, in _load_config
ignore_keys=self._preconf_set_by_auto, prefix=self.namespace,
File "c:\users\yevge\appdata\local\programs\python\python36-32\lib\site-packages\celery\app\utils.py", line 255, in detect_settings
for key in sorted(really_left)
celery.exceptions.ImproperlyConfigured:
Cannot mix new setting names with old setting names, please
rename the following settings to use the old format:
include -> CELERY_INCLUDE
Or change all of the settings to use the new format :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2018-07-26
@dimonchik2013

Cannot mix new setting names with old setting name...
in Celery, the format has changed, you need all the parameters to be called either in the old or in the new way

V
Vladimir Moroz, 2020-01-10
@Vladimyr1991

celery.conf.update(app.config- parenthesis missing?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question