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 to be triggered by the receiver.
Tip
You should refrain from modifying any application data in the signals because signals are not 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 inbuilt support for blinker
and uses signaling to a good extent. There are certain core signals provided by Flask.
In this recipe, we will use the application from the Full-text search with Elasticsearch recipe and make the addition of the product
and category
documents to indexes work via signals.
How to do it…
First, we need to create signals for the product and category creation...