Changeset 251


Ignore:
Timestamp:
Oct 29, 2009, 6:05:03 PM (11 years ago)
Author:
zerodeux
Message:

Many bugfixes, add -x/debug, add mail cron-style support

Location:
jobq
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • jobq/NEWS

    r250 r251  
    55    * Documented options in help
    66    * Tidying queue listing (un-quoting command as in queue runner logger)
    7     * (TODO) Added mail output a la cron
     7    * Added mail output a la cron (requires mailx)
     8    * Fixed todo=-1 info when queue was empty
     9    * Added (undocumented) -x debug option (don't detach daemon from tty)
     10    * Fixed a race condition in list_jobs where a job spec could be removed
     11      after being listed
     12    * Parse all options before calling run_daemon
     13    * Better logging: displaying user/queue/jobid instead of only jobid
    814
    915jobq 0.5
  • jobq/TODO

    r236 r251  
    1 * Job deletion
    2 * Queue runner stop
     1* Job cancelation
     2* Queue runner list/stop
     3* Interrupt idle 'sleep 5' to chain jobs immediatly
  • jobq/debian/control

    r236 r251  
    88Package: jobq
    99Architecture: all
    10 Depends: bash (>= 3.2), ${shlibs:Depends}, ${misc:Depends}
     10Depends: bash (>= 3.2), mailx, ${shlibs:Depends}, ${misc:Depends}
    1111Description: Simple job queue
    1212 jobq handles any nimber of job queues, where jobs are run as soon
  • jobq/jobq

    r250 r251  
    3333    ls -1rt | \
    3434    while read job; do
    35         jobt=`stat -c%y $job | cut -d. -f1`
    36         printf "%5s %20s  " $job "$jobt"
    37         sed 's/\\\([^\]\)/\1/g' <$job
     35        jobt=`stat -c%y $job 2>/dev/null | cut -d. -f1`
     36        jobp=`sed 's/\\\([^\]\)/\1/g' $job 2>/dev/null`
     37        if [ -n "$jobp" ]; then
     38            printf "%5s %20s  %s" $job "$jobt" "$jobp"
     39        fi
    3840    done
    3941}
     
    5658 
    5759    # Automatically start queue runner
    58     cd - >/dev/null && exec $0 -q $queue -d
     60    cd - >/dev/null && exec $0 -q $queue -d $debug
    5961}
    6062
    6163queue_runner() {
    62     trap ":" INT HUP
    63     exec </dev/null 2>/dev/null >/dev/null
     64    if [ -z "$debug" ]; then
     65        trap ":" INT HUP
     66        exec </dev/null 2>/dev/null >/dev/null
     67    fi
    6468
    6569    while true; do
     
    7276            job=`basename "$job"`       # job ID
    7377            jobt=`stat -c%Y $job`       # job submission time
    74             todo=`echo "$jobl" |wc -l`  # job queue size
    7578            rm $job                     # remove the job, it _will_ be run in a few lines
    76             todo=$(( $todo - 1 ))
     79            todo=`echo "$jobl" |wc -l`  # new job queue size
    7780
    7881            # Run job in a subshell, capture stdin+stderr, send to syslog
    79             # FIXME: should support mail output like cron
    80             export jobt todo
     82            export cmd jobt todo
    8183            (
    8284                t0=`date +%s`
    8385                late=$(( $t0 - $jobt ))
    84                 echo -n "start (delay:$late sec, todo:$todo): "
    85                 echo "$cmd" | sed 's/\\\([^\]\)/\1/g'
    86                 eval $cmd 2>&1
     86                jobp=$(echo "$cmd" | sed 's/\\\([^\]\)/\1/g')
     87                echo "start (delay:$late sec, todo:$todo): $jobp"
     88                if [ -z "$MAILTO" ]; then
     89                    eval $cmd 2>&1
     90                else
     91                    eval $cmd 2>&1 | mailx -E -s "`hostame -f` job[$LOGNAME/$queue/$job]: $jobp" $MAILTO
     92                fi
    8793                ret=$?
    8894                dt=$(( `date +%s` - $t0 ))
    8995                echo "done (time:$dt sec, exit:$ret)"
    90             ) | logger -t "job[$job]"
     96            ) | logger -t "job[$LOGNAME/$queue/$job]"
    9197        else
    9298            # No job, re-scan the queue later
     
    108114    rm -f $pidfile
    109115
    110     export queue pidfile
     116    export debug queue pidfile
    111117    queue_runner &
    112118
    113119    pid=$!
    114120    echo $pid > $pidfile
    115     echo "queue runner started for '$queue' (pid $pid)" | logger -t $PROGRAM
     121    echo "queue runner started for user/queue '$LOGNAME/$queue' (pid $pid)" | logger -t $PROGRAM
    116122}
    117123
     
    122128
    123129The default queue is called, er, 'default'. One 'queue runner' daemon is
    124 needed per queue, and is started automatically upon first job submission.
    125 There is no mechanism to stop a queue runner besides killing it for now.
     130needed per queue and per user, and is started automatically upon first job
     131submission. There is no mechanism to stop a queue runner besides killing it.
     132
     133If MAILTO is set, job output (if any) is sent to this address, otherwise it
     134is syslogged to the user.info facility. This is a queue runner setting,
     135either parsed by explicit queue runner start, either while running the first
     136job for a given user/queue.
    126137
    127138Options:
     
    140151
    141152queue=default
     153daemon=
     154debug=
    142155
    143156parse_opt=run
    144157while [ $parse_opt != "done"  ] ; do
    145158    case "$1" in
    146         -d|--daemon)  run_daemon;;
     159        -d|--daemon)  shift; daemon=yes;;
    147160        -q|--queue)   shift; queue="$1"; shift;;
    148161        -h|--help)    help;;
    149162        -v|--version) version;;
     163        -x)           shift; debug="-x";;
    150164
    151165        --) parse_opt=done;;
     
    155169done
    156170
    157 
     171if [ -n "$daemon" ]; then
     172    run_daemon
     173fi
    158174if [ $# -gt 0 ]; then
    159175    add_job "$@"
Note: See TracChangeset for help on using the changeset viewer.