This is an in detail guide for developers, who are looking forward to understand how the workflows work within Diffgram and implement custom actions themselves.
- Be familiar with Diffgram codebase, if not first see new engineer welcome
- Good understanding of how RabbitMQ works
- Have a Diffgram dev installation (this is optional, but it's good to have it if you want to try it yourself)
Let's start from the very beginning: where do the event handler is actually initiated?
If you head to the eventhandlers/main.py, you can see the initialisation of the ConsumerCreator class, and after call of consumer_creator.start_processing() - from this point any Event in Diffgram will be handled by that class.
Now, if we move to the eventhandlers/startup/ConsumersCreator.py we will see that there are 2 types of the consumers there: EventsConsumer and ActionsConsumer, and as you probably have guessed already, ActionsConsumer is the one that is responsible for the handling actions, however it's not that simple.
To trigger any action, first we need to emit an event which this action is linked to. For example, it can be file upload, task completion etc. This event will go to process_new_event method of the EventsConsumer, where it will check if there are any actions linked to that event type, if yes - we loop through the linked action types, and sending messages to the RabbitMQ , which will be consumed by the ActionsConsumer
Finally, let's execute the action. In the eventhandlers/startup/ActionConsumer.py you will find class that is really similar to the one that was handling events. In the process_action_trigger_event method we are doing next:
- Querying actions of the give type from the database
- Filtering them to execute ones that belong to the active workflows
- Looping through the actions and executing them one by one
To understand how to implement and execute custom actions, check out this guide
Updated 4 months ago