Changeset 238


Ignore:
Timestamp:
Oct 20, 2009, 12:35:22 AM (11 years ago)
Author:
zerodeux
Message:

0.3: fixes job unquoting, signal trapping and indentation

Location:
jobq
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • jobq/CHANGES

    r237 r238  
     1jobq 0.3
     2
     3        * Really trapping INT and HUP signals now
     4        * Fix job command unquoting
     5        * Fix indentation, gotta get used to 4 whitespaces
     6
    17jobq 0.2
    28
  • jobq/debian/changelog

    r237 r238  
     1jobq (0.3-1) stable; urgency=low
     2
     3  * Upstream update.
     4
     5 -- Vincent CARON <vcaron@bearstech.com>  Tue, 20 Oct 2009 00:33:05 +0200
     6
    17jobq (0.2-1) stable; urgency=low
    28
  • jobq/jobq

    r237 r238  
    2525
    2626list_jobs() {
    27   cd $JOBPATH/$queue 2>/dev/null || exit 0
    28   echo "ID     Submission date      Command"
    29   ls -1rt | \
    30   while read job; do
    31     jobt=`stat -c%y $job | cut -d. -f1`
    32     printf "%5s %20s  " $job "$jobt"
    33     cat $job
    34   done
     27    cd $JOBPATH/$queue 2>/dev/null || exit 0
     28    echo "ID     Submission date      Command"
     29    ls -1rt | \
     30    while read job; do
     31        jobt=`stat -c%y $job | cut -d. -f1`
     32        printf "%5s %20s  " $job "$jobt"
     33        cat $job
     34    done
    3535}
    3636
    3737add_job() {
    38   set -e
    39   mkdir -m 0700 -p $JOBPATH/$queue
    40   cd $JOBPATH/$queue
     38    set -e
     39    mkdir -m 0700 -p $JOBPATH/$queue
     40    cd $JOBPATH/$queue
    4141
    42   # Hopefully this 'mv' is atomic, thus our joblist is lock-free
    43   id=$$
    44   echo "$*" >.$id && mv .$id $id
     42    # Command line args re-quote - you don't want to know this shell ugliness.
     43    argv=
     44    for a in "$@"; do
     45        qa=$(printf %q "$a")
     46        argv="$argv$qa "
     47    done
    4548
    46   # Automatically start queue runner
    47   cd - >/dev/null && exec $0 -q $queue -d
     49    # Hopefully this 'mv' is atomic, thus our joblist is lock-free
     50    id=$$
     51    echo "$argv" >.$id && mv .$id $id
     52 
     53    # Automatically start queue runner
     54    cd - >/dev/null && exec $0 -q $queue -d
    4855}
    4956
    5057queue_runner() {
    51 #  trap ":" INT HUP
    52   exec </dev/null 2>/dev/null >/dev/null
     58    trap ":" INT HUP
     59    exec </dev/null 2>/dev/null >/dev/null
    5360
    54   while true; do
    55     # Fetch older job file
    56     job=`ls -1rt 2>/dev/null | head -n1`
     61    while true; do
     62        # Fetch older job file
     63        job=`ls -1rt 2>/dev/null | head -n1`
    5764
    58     if [ -n "$job" ]; then
    59       cmd=`cat $job`         # content of job file, the commande to run
    60       job=`basename "$job"`  # job ID
    61       jobt=`stat -c%Y $job`  # job submission time
    62       rm $job                # remove the job, it _will_ be run in a few lines
     65        if [ -n "$job" ]; then
     66            cmd=`cat $job`         # content of job file, the commande to run
     67            job=`basename "$job"`  # job ID
     68            jobt=`stat -c%Y $job`  # job submission time
     69            rm $job                # remove the job, it _will_ be run in a few lines
    6370
    64       # Run job in a subshell, capture stdin+stderr, send to syslog
    65       export jobt
    66       (
    67         t0=`date +%s`
    68         late=$(( $t0 - $jobt ))
    69         echo "starting (delay=$late sec): $cmd"
    70         $cmd 2>&1
    71         ret=$?
    72         dt=$(( `date +%s` - $t0 ))
    73         echo "done (exit=$ret, time=$dt sec)"
    74       ) | logger -t "job[$job]"
    75     else
    76       # No job, re-scan the queue later
    77       sleep 5
    78     fi
    79   done
     71            # Run job in a subshell, capture stdin+stderr, send to syslog
     72            export jobt
     73            (
     74                t0=`date +%s`
     75                late=$(( $t0 - $jobt ))
     76                echo "starting (delay=$late sec): $cmd"
     77                eval $cmd 2>&1
     78                ret=$?
     79                dt=$(( `date +%s` - $t0 ))
     80                echo "done (exit=$ret, time=$dt sec)"
     81            ) | logger -t "job[$job]"
     82        else
     83            # No job, re-scan the queue later
     84            sleep 5
     85        fi
     86    done
    8087}
    8188
     
    110117needed per queue, and is started automatically upon first job submission.
    111118EOF
    112   exit 1
     119    exit 1
    113120}
    114121
     
    128135
    129136if [ $# -gt 0 ]; then
    130     add_job $*
     137    add_job "$@"
    131138else
    132139    list_jobs
Note: See TracChangeset for help on using the changeset viewer.