-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool.inc
executable file
·38 lines (35 loc) · 1.19 KB
/
pool.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
POOL_N=0
POOL_LOCKED=0
POOL_CNT=0
function wait_if_necessary {
amount=$1
output=$2
while
count=`jobs -rp | wc -l`
do_wait1=$(($count >= $amount))
if [ -f lock ]; then do_wait2=1; POOL_LOCKED=`expr $POOL_LOCKED \+ 1`; else do_wait2=0; POOL_LOCKED=0; fi
if [ "$do_wait1" -eq "1" -a "$count" -gt "$POOL_CNT" ]; then
echo "Now $count jobs are running, wait..."
[ ! -z "$output" ] && sleep 3 && id=$(grep 'Job ID' ${output}.${POOL_N}) && echo "NOTE: last submitted was:" $id
fi
if [ "$do_wait2" -eq "1" -a "$POOL_LOCKED" -eq "1" ]; then
echo "Lock file found, wait..."
fi
POOL_CNT=$count
sleep 1
[ "$do_wait1" -eq 1 -o "$do_wait2" -eq 1 ]
do
continue;
done
}
function run_task {
cmd=$1
output=$2
concurency=$3
wait_if_necessary $concurency $output
count=`jobs -rp | wc -l`
count=`expr $count \+ 1`
POOL_N=$(expr ${POOL_N} \+ 1)
echo "New active task #$count: $cmd > ${output}.${POOL_N}"
$cmd > ${output}.${POOL_N} && touch ${output}.${POOL_N}.done &
}