Skip to content

Instantly share code, notes, and snippets.

@sigismund
Last active August 3, 2020 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sigismund/ab5ed86fc322d2d1ee5b7d451ce1e5f7 to your computer and use it in GitHub Desktop.
Save sigismund/ab5ed86fc322d2d1ee5b7d451ce1e5f7 to your computer and use it in GitHub Desktop.
Check if wp action-scheduler ("cron") tasks are already running
#!/bin/bash
SERVICE="wp-cli action-scheduler"
MAX_RUNNING_SCHEDULERS=3
WP_CLI_PATH="/usr/local/bin/wp"
if (( $(ps aux | grep '/bin/wp action-scheduler' | grep -v 'grep' | wc -l) >= MAX_RUNNING_SCHEDULERS ))
then
echo "$SERVICE tasks are running at it's limit ($MAX_RUNNING_SCHEDULERS)."
else
echo "$SERVICE tasks are NOT running at it's limit ($MAX_RUNNING_SCHEDULERS)."
echo "$($WP_CLI_PATH run --batch-size=5 --batches=6 2>&1)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment