title: Flask RESTful create_app using Celery Problem
body: <p>I am new to Python Flask RESTful API. Now the project that I'm working on was pre built from the previous developers. I am able to put more logic into this project. Now as requirements goes I need to use CELERY for extensive calculations. I went through different articles in the WEB (e.g. <a href="https://blog.miguelgrinberg.com/post/celery-and-the-flask-application-factory-pattern" rel="nofollow noreferrer">https://blog.miguelgrinberg.com/post/celery-and-the-flask-application-factory-pattern</a>) and other articles here but still no luck on this.</p>
  
  <pre><code>[repo: tracker/]
     __init.py__
     app.py
     config.py
     models.py
     celery.py
     tasks.py
     /resources/locate.py
     /resources/create.py
  </code></pre>
  
  <p><strong>init</strong>.py - has the following contents:</p>
  
  <pre><code>from tracker import app
  </code></pre>
  
  <p>app.py - has the following contents:</p>
  
  <pre><code>from tracker.resources.locate import Locate
  from tracker.resources.create import Create
  
  from .celery import create_celery
  from .redis_repo import redis_store
  from .config import app_config
  from .models import db
  
  import collections
  
  def create_app(config_name):
  
      app = Flask(__name__)
      app.config.from_object(app_config[config_name])
  
      api = Api(app, catch_all_404s=True)
      api.add_resource(Locate, '/api/v1/locate/&lt;string:ud&gt;', methods=['GET'])
      api.add_resource(Create, '/api/v1/create/&lt;string:ud&gt;', methods=['GET','POST'])
  
      redis_store.init_app(app)
      db.init_app(app)
  
         return app
  
      app = create_app('development')
  
      if __name__ == '__main__':
          app.run(threaded=True, debug=False)
  </code></pre>
  
  <p>config.py - has the following contents:</p>
  
  <pre><code>import tempfile
  
  class DevelopmentConfig(Config):
      DEBUG = True
      SQLALCHEMY_POOL_SIZE = 10
      SQLALCHEMY_DATABASE_URI = 'postgres://xxx'
      REDIS_URL = "redis://127.0.0.1:32769/0" 
      CELERY_BROKER_URL = "redis://127.0.0.1:32769/0"
      CELERY_BACKEND = "db+postgresql://xxx" 
  
  app_config = {'development': DevelopmentConfig}
  </code></pre>
  
  <p>models.py - has the following contents:</p>
  
  <pre><code>from flask_sqlalchemy import SQLAlchemy
  from sqlalchemy import func, exc, or_
  import datetime
  from sqlalchemy_utils import UUIDType
  
  import tracker
  
  db = SQLAlchemy()
  
  class T_Logs(db.Model)
        ....
        ....
        ....    
  </code></pre>
  
  <p>locate.py - has the following contents:</p>
  
  <pre><code>from flask import request, current_app, jsonify, after_this_request
  from flask_restful import Resource
  from sqlalchemy import exc
  
  from tracker import models, config, redis_repo, utility
  from datetime import datetime, timedelta
  
  import uuid, json
  
  class Locate(Resource):
  
      def get(self, ud):
      ....
      ....    
  </code></pre>
  
  <p>Using those documentations or tutorials, it's quite easy to run and understand how these works. But putting it altogether in our implementations it doesnt seem to work.</p>
  
  <p>with celery.py</p>
  
  <pre><code>from celery import Celery
  
  def create_celery(app=None):
      application = app or create_app
      celery = Celery(app.import_name,
                      broker=app.config['CELERY_BROKER_URL'])
      celery.conf.update(app.config)
      TaskBase = celery.Task
  
      class ContextTask(TaskBase):
          abstract = True
  
          def __call__(self, *args, **kwargs):
              with application.app_context():
                  return TaskBase.__call__(self, *args, **kwargs)
  
      celery.Task = ContextTask
      return celery
  </code></pre>
  
  <p>And sample tasks.py</p>
  
  <pre><code>from app import create_celery
  
  @celery.task(name="tasks.add")
  def add(a,b):
      return a+ b
  </code></pre>
  
  <p>So when I run these via visual studio code, I dont see any errors or warnings.
  But when i run this on the other command prompt to start the worker:</p>
  
  <pre><code>celery -A app.tasks.add worker -l info -P eventlet
  </code></pre>
  
  <p>It saying
          from tracker.resources.locate import Locate
          ModuleNotFoundError: No module named 'tracker'</p>
  
  <p>It never get executed. I'm not yet trying to call the tasks on the resources yet, But I cant proceed yet to understand how to do this.</p>
  
  <p>If anyone could possibly enlighten me with this it would be greatly appreciated.</p>