Async CPM Development and "My Code's Not Updating!"

The Issue

While developing asynchronous CPMs, you'll notice that when you make a code change, the site logic may or may not update immediately. In fact, sometimes you may run the CPM and it will appear to use your old code, then the next time it will use your new code, then vice-versa! This is due to the fact that Oracle 'caches' the async code in memory on their utility servers, and will only retrieve the new version of the code when the utility server PHP process ends. These processes may run for many minutes, and handle numerous batches of async CPM 'runs'. Depending on the current load on the shared utility servers, any of the servers may pick up the async request and run it in its queue, which is why you may see each subsequent run switch between using your new and old code.

The Workaround

I have not found a consistent way to work around this and force the utility servers to start a new process with the latest code, without simply waiting for the processes to start again naturally. But if you implement a logging system and update your log every code update with a new version number or timestamp, you can at least determine when exactly your new code is being run and remove the guesswork from debugging.

If you are using the CP library code-management approach as I've discussed previously, you may think that simply re-deploying the template code in the Process Designer would cause a refresh of the utility server processes, but this does not appear to be the case.

The Upside

One incredibly useful tool, as a result of how the async CPM queue works, is that you can leverage static methods and properties on your CPM classes to cache data for the entire length of the PHP process. This allows you to optimize your async CPMs, for instance: you can query any configuration data from the database once, store it in a static property, and access it without making another database hit for any other CPMs that run on that same PHP process!

Zircon - This is a contributing Drupal Theme
Design by WeebPal.