In this chapter, we looked at some of the ways we as module developers can set up simple and complex data processing tasks that can run at any time we want.
We started by looking into using the multirequest capabilities of the update hooks. This was a continuation from Chapter 8, The Database API, where we introduced them for the first time, and we have now seen how we can expand on their capabilities. Then, we turned to the more complex Batch API that uses similar, albeit more complex, techniques. This system allowed us to construct a series of operations that leveraged Drupal's multirequest capabilities. Our playground was the JSON products Importer, which now can handle large amounts of data without the concern of PHP memory timeouts. Next, we looked at how Drupal's cron system works and why it is there, and even saw an example of how as module developers we can hook into it and process our own tasks whenever it runs. But then, we took things to the next level with the introduction of the Queue API, which allowed us to add items to a queue so that they can get processed at a later stage. This processing, as we saw, can be triggered by cron or we can take matters into our own hands and handle them one by one. Not to mention the Drush option that can also make things easy. Finally, we looked at the Lock API, which allows us to get control over the triggering of certain processes that take longer to complete. All this is done in order to prevent them being run multiple times simultaneously, causing errors or data corruption.
In the next chapter we are going to talk about Views and how we can programmatically interact with these as module developers.