@@ -52,12 +52,13 @@ class DrushBatchContext extends ArrayObject {
5252 * Process a Drupal batch by spawning multiple Drush processes.
5353 *
5454 * This function will include the correct batch engine for the current
55- * major version of Drupal, and will make use of the site-process
56- * library to spawn multiple worker threads to handle the processing of
57- * the current batch.
55+ * major version of Drupal, and will make use of the drush_backend_invoke
56+ * system to spawn multiple worker threads to handle the processing of
57+ * the current batch, while keeping track of available memory .
5858 *
5959 * The batch system will process as many batch sets as possible until
60- * the entire batch has been completed.
60+ * the entire batch has been completed or half of the available memory
61+ * has been used.
6162 *
6263 * This function is a drop in replacement for the existing batch_process()
6364 * function of Drupal.
@@ -195,14 +196,17 @@ function _drush_batch_command($id) {
195196 if (_drush_batch_worker ()) {
196197 return _drush_batch_finished ();
197198 }
199+ else {
200+ return ['drush_batch_process_finished ' => FALSE ];
201+ }
198202}
199203
200204
201205/**
202206 * Process batch operations
203207 *
204208 * Using the current $batch process each of the operations until the batch
205- * has been completed or half of the available memory for the process has been
209+ * has been completed or 60% of the available memory for the process has been
206210 * reached.
207211 */
208212function _drush_batch_worker () {
@@ -278,6 +282,15 @@ function _drush_batch_worker() {
278282 // At this point, either $current_set contains operations that need to be
279283 // processed or all sets have been completed.
280284 $ queue = _batch_queue ($ current_set );
285+
286+ // If we are in progressive mode, break processing after 60% of memory usage
287+ // is reached.
288+ if (drush_memory_limit () > 0 && (memory_get_usage () * 1.6 ) >= drush_memory_limit ()) {
289+ Drush::logger ()->notice (dt ("Batch process has consumed in excess of 50% of available memory. Starting new thread " ));
290+ // Record elapsed wall clock time.
291+ $ current_set ['elapsed ' ] = round ((microtime (TRUE ) - $ current_set ['start ' ]) * 1000 , 2 );
292+ break ;
293+ }
281294 }
282295
283296 // Reporting 100% progress will cause the whole batch to be considered
0 commit comments