When running commands against a large number of sites, we can run these tasks asynchronously because each site is independent. There are two ways of running asynchronous tasks:
- Asynchronous background shell commands
- Parallel shell commands
The general approach for this requires wrapping multiple Terminus commands into a single shell script that accepts a Site ID, which can then be used in a asynchronous loop or parallel method.
- Terminus Machine Token (
TERMINUS_MACHINE_TOKEN
) - SSH Key in PEM format (
PRIVATE_SSH_KEY
) - Pantheon Upstream UUID (
UPSTREAM_UUID
) - Pantheon Organization UUID (
ORG_UUID
) - Slack Webhook URL (
SLACK_WEBHOOK
)
- Prepare the build environment
- Authenticate Terminus
- Generate list of site UUIDs
- Asynchronously process sites
- Async Background Processes
Utilize
&
to send shell process to the background, add delay (sleep
) between processes, wait for all background processes to finish (usewait
). - Parallel Processing Pipe site IDs to GNU Parallel, set max jobs capacity, pass site ID to script, wait for job queue to complete.
- Async Background Processes
Utilize
You will need to have the private SSH key (associated with the user issued the Terminus Machine Token) added as a secret repo variable, because it will be used to authenticate any Terminus application commands (Drush or WP CLI).