Add max batch size CLI option

This commit is contained in:
Vincent Riquer 2013-09-28 00:11:31 +02:00
parent 5e006ae7cc
commit 00dd038f7b

21
atom
View File

@ -65,6 +65,7 @@ help() {
-T <seconds> override load-interval
-F <destination> Force re-generation of all files in
<destination>
-B <batch size> Create/update no more than <batch size> 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