Working with signals
Signals can be thought of as events that happen in our application. These events can be subscribed by certain receivers who then invoke a function whenever the event occurs. The occurrence of events is broadcasted by senders who can specify the arguments that can be used by the function, which will be triggered by the receiver.
Important
You should refrain from modifying any application data in the signals because signals aren’t executed in a specified order and can easily lead to data corruption.
Getting ready
We will use a Python library called blinker
, which provides the signals feature. Flask has built-in support for blinker
and uses signaling itself to a good extent. There are certain core signals provided by Flask.
In this recipe, we will use the application from the Implementing full-text search with Elasticsearch recipe and add the product
and category
documents to make indexes work via signals.
How to do it…
Follow these...