Skip to content

Instantly share code, notes, and snippets.

@sjelfull
Created June 5, 2017 13:37
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 sjelfull/4f80e0ac461573ab493e229a25be2934 to your computer and use it in GitHub Desktop.
Save sjelfull/4f80e0ac461573ab493e229a25be2934 to your computer and use it in GitHub Desktop.
Parallel processing in Craft with parallel
#!/bin/bash
LOCAL_PARALLEL_JOBS=$1
PARALLEL_JOBS=${LOCAL_PARALLEL_JOBS:-4}
# parallel creates a subshell, which will use the default $SHELL
# This makes sure php runs paralell with the correct shell
export SHELL=/bin/bash
index() {
echo Indexing $1
# echo `craft/app/etc/console/yiic elasticsearch test --id=$1`
craft/app/etc/console/yiic elasticsearch mapEntry --id=$1
echo Done with $1
}
export -f index
# Make sure logs directory exists
if [ ! -d "logs" ]; then
mkdir logs
fi
# Save ids to txt file
craft/app/etc/console/yiic elasticsearch saveEntryIds
# Map entry content to json files
cat data/entries/ids.txt | parallel --progress --eta --joblog logs/parallel-es-indexing.log -j $PARALLEL_JOBS index
# Index json files
craft/app/etc/console/yiic elasticsearch indexJsonFiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment