Manager

flask_worker.Manager

class flask_worker.Manager(app=None, **kwargs) [source]

Flask extension which manages workers. The manager tracks an application import path, a redis connection, the application database, and the web socket. These tools will be invoked by workers.

Parameters: app : flask.app.Flask or None, default=None

Flask application for whose workers the manager is responsible. If the app is passed to the contructor, the manager will be initialized with the application. Otherwise, you must perform the initialization later by calling init_app.

**kwargs :

You can set the manager's attributes by passing them as keyword arguments.

Attributes: app_import : str, default='app.app'

Pythonic import path for the Flask application. e.g. if your application object is created in a file path/to/app.py and named my_app, set the app_import to path.to.app.my_app.

connection : redis.client.Redis

Redis connection for the workers. If not explicitly set, the manager will set the connection attribute to the app's redis attribute. In this case, the app must have a redis connection attribute named redis when the manager is initialized with the application.

db : flask_sqlalchemy.SQLAlchemy

Database for the flask application.

loading_img_blueprint : str or None, default=None

Name of the blueprint to which the loading image belongs. If None, the loading image is assumed to be in the app's static directory.

loading_img_filename : str, default='worker_loading.gif'

Name of the loading image file. This should be in the app's static directory or a blueprint's static directory.

loadering_img_src : str

Loading image source path, derived from loading_img_blueprint and loading_img_filename.

socketio : flask_socketio.SocketIO or None, default=None

Socket object through which workers will emit job progress messages. While this argument is not required on initialization, it must be set before the app is run.

template : str, default='worker/worker_loading.html'

Name of the html template file for the loading page. Flask-Worker provides a default loading template.

Methods

init_app(self, app, **kwargs) [source]

Initialize the manager with the application.

Parameters: app : flask.app.Flask

Flask application for whose workers the manager is responsible.

**kwargs :

You can set the manager's attributes by passing them as keyword arguments.