title: Initializing Celery Worker from Flask application
body: <p>I have a Flask application that has the following:</p>
  <pre><code># src/tasks/CeleryClient.py
  
  from celery import Celery
  
  def make_celery(celery_app):
      celery = Celery(
          celery_app.import_name,
          backend=celery_app.config['CELERY_RESULT_BACKEND'],
          broker=celery_app.config['CELERY_BROKER_URL']
      )
      celery.conf.update(celery_app.config)
  
      class ContextTask(celery.Task):
          def __call__(self, *args, **kwargs):
              with celery_app.app_context():
                  return self.run(*args, **kwargs)
  
      celery.Task = ContextTask
      return celery
  </code></pre>
  <p>My tasks file looks like this:</p>
  <pre><code>src/tasks/NotificationTask.py
  
  notification_type_schema = NotificationTypeSchema()
  push_notification_schema = PushNotificationSchema()
  push_service = FCMNotification(api_key=AzureKeyVault.get_secret('firebase-server-key'))
  
  # Initialize Celery with Flask instance
  celery_flask = Flask(__name__)
  celery_flask.config.from_object(app_config[os.environ.get('FLASK_ENV')])
  celery = make_celery(celery_flask)
  
  @celery.task(bind=True)
  def init_push_notification(self, data):
      &quot;&quot;&quot;
      Send Push Notification Task
      &quot;&quot;&quot;
  </code></pre>
  <p>The code builds fine. The issue I am having is this is being run in a docker container and I would like to create two workers in this container (one is fine). I cannot seem to figure out how to programmatically create a worker.</p>
  <p>Finally my run.py looks like this:</p>
  <pre><code>import os
  from src.config import app_config
  from dotenv import load_dotenv, find_dotenv
  from src.app import create_app
  
  load_dotenv(find_dotenv())
  
  env_name = os.getenv('FLASK_ENV')
  app = create_app(env_name)
  
  &quot;&quot;&quot;
  Push app context, needed for reindexing
  and db functions at the command line
  app.app_context().push()
  &quot;&quot;&quot;
  
  if __name__ == '__main__':
    port = os.getenv('PORT')
    # run app
    app.run(app, host='0.0.0.0', port=port, threaded=True, debug=True)
  </code></pre>
  <p>Any pointers would be great, thanks so much.</p>