Changeset 253


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

indent fix (from my point of view)

Location:
jobq
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • jobq/NEWS

    r251 r253  
     1jobq 0.7 (unreleased)
     2
     3    * Changed indent from 4ws to 2ws (I'm too used to id)
     4
    15jobq 0.6
    26
  • jobq/jobq

    r252 r253  
    2222
    2323PROGRAM=jobq
    24 VERSION=0.6
     24VERSION=0.7-dev
    2525
    2626# Hardcoded value for now, should fit most people
     
    2929
    3030list_jobs() {
    31     cd $JOBPATH/$queue 2>/dev/null || exit 0
    32     echo "ID     Submission date      Command"
    33     ls -1rt | \
    34     while read job; do
    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
    40     done
     31  cd $JOBPATH/$queue 2>/dev/null || exit 0
     32  echo "ID     Submission date      Command"
     33  ls -1rt | \
     34  while read job; do
     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
     40  done
    4141}
    4242
    4343add_job() {
    44     set -e
    45     mkdir -m 0700 -p $JOBPATH/$queue
    46     cd $JOBPATH/$queue
     44  set -e
     45  mkdir -m 0700 -p $JOBPATH/$queue
     46  cd $JOBPATH/$queue
    4747
    48     # Command line args re-quote - you don't want to know this shell ugliness.
    49     argv=
    50     for a in "$@"; do
    51         qa=$(printf %q "$a")
    52         argv="$argv$qa "
    53     done
     48  # Command line args re-quote - you don't want to know this shell ugliness.
     49  argv=
     50  for a in "$@"; do
     51    qa=$(printf %q "$a")
     52    argv="$argv$qa "
     53  done
    5454
    55     # Hopefully this 'mv' is atomic, thus our joblist is lock-free
    56     id=$$
    57     echo "$argv" >.$id && mv .$id $id
     55  # Hopefully this 'mv' is atomic, thus our joblist is lock-free
     56  id=$$
     57  echo "$argv" >.$id && mv .$id $id
    5858 
    59     # Automatically start queue runner
    60     cd - >/dev/null && exec $0 -q $queue -d $debug
     59  # Automatically start queue runner
     60  cd - >/dev/null && exec $0 -q $queue -d $debug
    6161}
    6262
    6363queue_runner() {
    64     if [ -z "$debug" ]; then
    65         trap ":" INT HUP
    66         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
     68
     69  while true; do
     70    # Fetch job list in time order, older is first
     71    jobl=`ls -1rt 2>/dev/null`
     72    job=`echo "$jobl" | head -n1`
     73
     74    if [ -n "$job" ]; then
     75      cmd=`cat $job`              # content of job file, the command to run
     76      job=`basename "$job"`       # job ID
     77      jobt=`stat -c%Y $job`       # job submission time
     78      rm $job                     # remove the job, it _will_ be run in a few lines
     79      todo=`echo "$jobl" |wc -l`  # new job queue size
     80
     81      # Run job in a subshell, capture stdin+stderr, send to syslog
     82      export cmd jobt todo
     83      (
     84        t0=`date +%s`
     85        late=$(( $t0 - $jobt ))
     86        jobp=$(echo "$cmd" | sed 's/\\\([^\]\)/\1/g')
     87        echo "start (delay:$late sec, todo:$todo): $jobp"
     88
     89        if [ -z "$MAILTO" ]; then
     90          eval $cmd 2>&1
     91        else
     92          eval $cmd 2>&1 | mailx -E -s "`hostame -f` job[$LOGNAME/$queue/$job]: $jobp" $MAILTO
     93        fi
     94        ret=$?
     95
     96        dt=$(( `date +%s` - $t0 ))
     97        echo "done (time:$dt sec, exit:$ret)"
     98      ) | logger -t "job[$LOGNAME/$queue/$job]"
     99    else
     100      # No job, re-scan the queue later
     101      sleep 5
    67102    fi
    68 
    69     while true; do
    70         # Fetch job list in time order, older is first
    71         jobl=`ls -1rt 2>/dev/null`
    72         job=`echo "$jobl" | head -n1`
    73 
    74         if [ -n "$job" ]; then
    75             cmd=`cat $job`              # content of job file, the command to run
    76             job=`basename "$job"`       # job ID
    77             jobt=`stat -c%Y $job`       # job submission time
    78             rm $job                     # remove the job, it _will_ be run in a few lines
    79             todo=`echo "$jobl" |wc -l`  # new job queue size
    80 
    81             # Run job in a subshell, capture stdin+stderr, send to syslog
    82             export cmd jobt todo
    83             (
    84                 t0=`date +%s`
    85                 late=$(( $t0 - $jobt ))
    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
    93                 ret=$?
    94                 dt=$(( `date +%s` - $t0 ))
    95                 echo "done (time:$dt sec, exit:$ret)"
    96             ) | logger -t "job[$LOGNAME/$queue/$job]"
    97         else
    98             # No job, re-scan the queue later
    99             sleep 5
    100         fi
    101     done
     103  done
    102104}
    103105
    104106run_daemon() {
    105     cd $JOBPATH/$queue
     107  cd $JOBPATH/$queue
    106108
    107     pidfile=.runner
    108     pid=`cat $pidfile 2>/dev/null`
    109     if kill -0 "$pid" 2>/dev/null; then
    110         # OK, queue runner is alive for this queue
    111         exit 0
    112     fi
    113     # No queue runner at all or some dead pid, cleanup
    114     rm -f $pidfile
     109  pidfile=.runner
     110  pid=`cat $pidfile 2>/dev/null`
     111  if kill -0 "$pid" 2>/dev/null; then
     112    # OK, queue runner is alive for this queue
     113    exit 0
     114  fi
     115  # No queue runner at all or some dead pid, cleanup
     116  rm -f $pidfile
    115117
    116     export debug queue pidfile
    117     queue_runner &
     118  export debug queue pidfile
     119  queue_runner &
    118120
    119     pid=$!
    120     echo $pid > $pidfile
    121     echo "queue runner started for user/queue '$LOGNAME/$queue' (pid $pid)" | logger -t $PROGRAM
     121  pid=$!
     122  echo $pid > $pidfile
     123  echo "queue runner started for user/queue '$LOGNAME/$queue' (pid $pid)" | logger -t $PROGRAM
    122124}
    123125
    124126help() {
    125     cat << EOF
     127  cat << EOF
    126128List queue: $PROGRAM [-q <queue>]
    127129Submit job: $PROGRAM [-q <queue>] command args ...
     
    142144  -v, --version      Show this software revision
    143145EOF
    144     exit 1
     146  exit 1
    145147}
    146148
    147149version() {
    148     echo "$PROGRAM $VERSION"
    149     exit 0
     150  echo "$PROGRAM $VERSION"
     151  exit 0
    150152}
    151153
     
    156158parse_opt=run
    157159while [ $parse_opt != "done"  ] ; do
    158     case "$1" in
    159         -d|--daemon)  shift; daemon=yes;;
    160         -q|--queue)   shift; queue="$1"; shift;;
    161         -h|--help)    help;;
    162         -v|--version) version;;
    163         -x)           shift; debug="-x";;
     160  case "$1" in
     161    -d|--daemon)  shift; daemon=yes;;
     162    -q|--queue)   shift; queue="$1"; shift;;
     163    -h|--help)    help;;
     164    -v|--version) version;;
     165    -x)           shift; debug="-x";;
    164166
    165         --) parse_opt=done;;
    166         -*) echo "$PROGRAM: unknown option $1, try -h for help" >&2; exit 2;;
    167          *) parse_opt=done;;
    168     esac
     167    --) parse_opt=done;;
     168    -*) echo "$PROGRAM: unknown option $1, try -h for help" >&2; exit 2;;
     169     *) parse_opt=done;;
     170  esac
    169171done
    170172
    171173if [ -n "$daemon" ]; then
    172     run_daemon
     174  run_daemon
    173175fi
    174176if [ $# -gt 0 ]; then
    175     add_job "$@"
     177  add_job "$@"
    176178else
    177     list_jobs
     179  list_jobs
    178180fi
Note: See TracChangeset for help on using the changeset viewer.