Workers
flask_worker.WorkerMixin
class flask_worker.WorkerMixin(template=None, **kwargs) [source]
The worker executes a complex task using a Redis queue. When called, it enqueues a job and returns a loading page.
When a Redis worker grabs the enqueued job, it executes the worker's
function, func
, passing in the worker's args
and kwargs
. After
execution, the worker's script replaces the client's window location with
a call to its callback
view function.
Parameters: | template : str or None, default=None
Name of the html template file for the worker's loading page. If You can set the worker's attributes by passing them as keyword arguments. |
---|---|
Attributes: | manager : flask_worker.Manager
The worker's manager. func : callableFunction which the worker will execute. args : list, default=[]Arguments which will be passed to the executed method. kwargs : dict, default={}Keyword arguments which will be passed to the executed method. callback : str or None, default=None
Name of the view function to which the client will navigate once the worker has finished its job. If Indicates that the worker has finished its job. job_in_progress : bool, default=FalseIndicates that the worker has a job in progress. job_id : strIdentifier for the worker's job. loading_page : sqlalchemy_mutablesoup.MutableSoupLoading page which will be displayed to the client while the worker performs its job. loading_img : bs4.Tag
Source of the loading image. result :Output of the worker's function. This stores the result of the job the worker executed. |
Methods
reset(self) [source]
Clears the job_finished
, job_in_progress
, and job_id
attributes.
Returns: | self : flask_worker.WorkerMixin
|
---|
__call__(self) [source]
Enqueue the worker's job for execution if it is not enqueued already.
Returns: | loading_page : str (html)
The client's loading page. |
---|