From 00dd038f7b1fbedaf166631a1a8ba8bbe3415293 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Sat, 28 Sep 2013 00:11:31 +0200 Subject: [PATCH] Add max batch size CLI option --- atom | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/atom b/atom index d1c7316..fc6ef9b 100755 --- a/atom +++ b/atom @@ -65,6 +65,7 @@ help() { -T override load-interval -F Force re-generation of all files in + -B Create/update no more than files -S Run setup -h Show this text -D Increase debug @@ -74,7 +75,7 @@ help() { #parse arguments OPTERR=0 -while getopts ':c:Cl:T:F:ShD' opt +while getopts ':c:Cl:T:F:B:ShDq' opt do case $opt in c) @@ -92,6 +93,9 @@ do F) forceall+=("$OPTARG") ;; + B) + maxbatch="$OPTARG" + ;; S) forcesetup=1 ;; @@ -429,6 +433,11 @@ echo ' AND mime_type_actions.destination_id = destinations.id AND mime_type_actions.action = 1;' >&3 read -u4 filecount +if [ -n "$maxbatch" ] && (( maxbatch < filecount )) +then + (( togo = filecount - maxbatch )) + filecount=$maxbatch +fi echo ' SELECT source_files.id, @@ -463,16 +472,17 @@ echo ' WHERE CAST(destination_files.last_change AS TEXT) <> CAST(source_files.last_change AS TEXT) AND mime_type_actions.destination_id = destinations.id - AND mime_type_actions.action = 1; - + AND mime_type_actions.action = 1' >&3 +(( maxbatch )) && echo "LIMIT $maxbatch" >&3 +echo '; SELECT "AtOM:NoMoreFiles";' >&3 read -u4 line while ! [[ $line = AtOM:NoMoreFiles ]] do decodefiles+=("$line::AtOM:SQL:Sep::") -(( cron )) || echo -n 'Creating tasks... ' read -u4 line done +(( cron )) || echo -n 'Creating tasks... ' echo 'BEGIN TRANSACTION;' >&3 for line in "${decodefiles[@]}" @@ -559,7 +569,8 @@ do tmpfile done echo 'COMMIT;' >&3 -echo -e "\rCreated ${count:-0} tasks for $filecount files (${copies:-0} immediate copies)" +(( cron )) || echo -n $'\r' +echo "Created ${count:-0} tasks for $filecount files ${togo:+($togo left) }(${copies:-0} immediate copies)" concurrency=$(( maxload / 2 )) (( concurrency )) || concurrency=1