From d3daff959338fc2523ddf54c899a4b2842895019 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Sun, 24 Mar 2013 04:33:42 +0100 Subject: [PATCH] time estimation --- atom | 69 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/atom b/atom index 78bedb8..eb0f89e 100755 --- a/atom +++ b/atom @@ -1034,7 +1034,7 @@ copyFile() { extension="${filename##*.}" commandline="cp -al \"$sourcepath/$filename\" \"$destdir/$destfile.$extension\"" commandline+=" 2>/dev/null" - commandline+=' || ' + commandline+=' AtOM:OR ' commandline+="cp -a \"$sourcepath/$filename\" \"$destdir/$destfile\"" copytaskid=$( Insert tasks <<-EOInsert @@ -1231,7 +1231,7 @@ worker() { rest=${rest#*|} destfilename=${rest%%|*} rest=${rest#*|} - if eval $commandline >/dev/null 2>>"$tempdir/errors.log" + if eval ${commandline/AtOM:OR/||} >/dev/null 2>>"$tempdir/errors.log" then echo "finished $taskid|$sourcefileid|$destfileid|$destfilename" else @@ -1269,7 +1269,6 @@ master() { then eval echo AtOM:Die '>&'$((100+workerid)) wait ${workers[workerid]} - break eval $((100+workerid))'>&-' eval $((200+workerid))'<&-' rm "$tempdir"/worker${workerid}{in,out} @@ -1330,7 +1329,7 @@ master() { unset workers[workerid] fi ;; - 'finished') + ?(f)'inished') (( active-- )) || true taskid=${workerquery%%|*} rest="${workerquery#*|}|" @@ -1343,14 +1342,14 @@ master() { if [ -n "$destfilename" ] then echo \ - "UPDATE destination_files" \ - "SET filename=\"$destfilename\"," \ - " last_change=(" \ - " SELECT last_change" \ - " FROM source_files" \ - " WHERE id=$sourcefileid" \ - " )" \ - "WHERE id=$destfileid;" \ + "UPDATE destination_files" \ + "SET filename=\"${destfilename//\"/\"\"}\"," \ + " last_change=(" \ + " SELECT last_change" \ + " FROM source_files" \ + " WHERE id=$sourcefileid" \ + " )" \ + "WHERE id=$destfileid;" \ >&3 fi ;; @@ -1405,7 +1404,7 @@ then fi getConfig -set -e +set -eH if (( debug )) then cat <<-EOF @@ -1768,6 +1767,7 @@ echo -e "\rCreated ${count:-0} tasks for $filecount files" rm -f "$tempdir"/worker* concurrency=$(( maxload / 2 )) +(( concurrency )) || concurrency=1 active=0 for (( i=0 ; i < concurrency ; i++ )) do @@ -1822,34 +1822,61 @@ do fi fi master + if ((taskcount - remaining)) + then + currenttime=$(date +%s) + secsremaining=$(( + remaining + * + (currenttime - starttime) + / + (taskcount - remaining) + )) + (( days = + secsremaining + / + ( 24*60*60 ) + )) || true + (( hours = + ( secsremaining - ( days*24*60*60 ) ) + / + ( 60*60 ) + )) || true + (( minutes = + ( secsremaining - ( ( days*24 + hours ) *60*60 ) ) + / + 60 + )) || true + fi echo -en "\rload: $humanload / $maxload" \ - " workers: $active / $concurrency" \ - " done: $(( (taskcount - remaining ) * 100 / taskcount ))%" \ - " $((taskcount - remaining)) of $taskcount ($failed failed)" + "workers: $active / $concurrency" \ + "done: $(( (taskcount - remaining ) * 100 / taskcount ))%" \ + "- $((taskcount - remaining)) of $taskcount ($failed failed)" \ + "${days}d ${hours}h${minutes}m " done endtime=$(date +%s) (( elapsedseconds = endtime - starttime )) (( days = - elapsedseconds + secsremaining / ( 24*60*60 ) )) || true (( hours = - ( elapsedseconds - ( days*24*60*60 ) ) + ( secsremaining - ( days*24*60*60 ) ) / ( 60*60 ) )) || true (( minutes = - ( elapsedseconds - ( ( days*24*60*60 ) + ( hours*60*60 ) ) ) + ( secsremaining - ( ( days*24 + hours ) *60*60 ) ) / 60 )) || true (( seconds = - elapsedseconds + secsremaining - - ( ( days*24*60*60 ) + ( hours*60*60 ) + ( minutes*60) ) + ( ( ( ( days*24 + hours ) *60 ) + minutes ) *60 ) )) || true echo -e "\rRan $taskcount tasks, $failed of which failed, in $days" \