Filter
uncanny-automator-pro
automator_async_concurrent_batches
Filters the maximum number of concurrent batches allowed for asynchronous automation processes.
add_filter( 'automator_async_concurrent_batches', $callback, 10, 1 );
Description
Filters the number of concurrent asynchronous batches Uncanny Automator can process. This hook allows developers to adjust the maximum number of batches processed simultaneously. Use this filter to increase or decrease the concurrency for performance tuning or to avoid server overload. The default value is 2.
Usage
add_filter( 'automator_async_concurrent_batches', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Adjust the number of concurrent async batches for Uncanny Automator Pro.
*
* This filter allows developers to override the default number of concurrent
* async batches that Uncanny Automator Pro will process. For instance,
* you might want to reduce this number on shared hosting environments to
* prevent resource exhaustion or increase it on powerful servers for faster
* processing.
*
* @since 7.1
*
* @param int $concurrent The current concurrent batch count.
*
* @return int The adjusted concurrent batch count.
*/
add_filter( 'automator_async_concurrent_batches', 'my_custom_automator_concurrent_batches', 10, 1 );
function my_custom_automator_concurrent_batches( $concurrent ) {
// Example: Reduce concurrent batches to 1 if the site is on shared hosting.
// In a real-world scenario, you'd have a more robust way to detect shared hosting.
// This is a simplified example.
if ( defined( 'IS_SHARED_HOSTING' ) && IS_SHARED_HOSTING ) {
return 1; // Limit to 1 concurrent batch on shared hosting
}
// Example: Increase concurrent batches to 4 on a specific staging site.
if ( defined( 'WP_ENVIRONMENT_TYPE' ) && 'staging' === WP_ENVIRONMENT_TYPE && 'my-staging-site.com' === $_SERVER['HTTP_HOST'] ) {
return 4; // Increase to 4 concurrent batches on a specific staging site
}
// Otherwise, return the default or what's already set by another filter.
// The original function in Uncanny Automator Pro uses max(), so we should respect that.
// However, this filter is meant to *set* the desired value, which is then compared.
// So, simply returning our desired value is correct here.
return $concurrent; // If no specific condition met, return the passed value, which will then be compared with max() in the original function.
}
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/core/classes/async-actions.php:1490
public function adjust_concurrent_batches( $concurrent ) {
$automator_concurrent = apply_filters( 'automator_async_concurrent_batches', 2 );
return max( (int) $concurrent, $automator_concurrent );
}