Add support for BatchOperations dependencies

Created on 27 March 2024, 8 months ago
Updated 27 June 2024, 5 months ago

Problem/Motivation

It would be helpful if a given BatchOperation (script) could declare dependencies on other BatchOperations so that an order could be enforced.
A - dependent B, C
Means A would not allow itself to run if B and C were not run first.

This would have to use the BatchOpLog for determining if BatchOperations were run and completed already.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States swirt Florida

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @swirt
  • πŸ‡ΊπŸ‡ΈUnited States mile23 Seattle, WA
  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    Crediting Mile23 for the suggestion of adding this.

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida
  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    There is some logic now present to determine if a batch operation has been run before. I am not clear if this need would be to only run A if B. and C were just run .. or if they were ever previously run.

    It is already possible through using the 'preBatchMethod($sandbox)' or 'postBatchMethod($sandbox)' to call another BatchOperation directly so a dependency could actually be performed.

    Maybe this just needs documentation as an example BatchOperation.

    Example:
    If A needed B and C to run first, then In the batch operation for A add the optional method

    public function preBatchMethod($sandbox) {
      $B = \Drupal::classResolver('\Drupal\YOUR_MODULE\cbo_scripts\B');
      $B->run($sandbox, 'hook_update');
    
      $C = \Drupal::classResolver('\Drupal\YOUR_MODULE\cbo_scripts\C');
      $C->run($sandbox, 'hook_update');
    
      return "I ran B and C.  They will each have their own logs that you should see.";
    }
    
Production build 0.71.5 2024