s4

changeset 622:5f1d4bbf9dea

smail_queue frequency control
author HIROSE Yuuji <yuuji@gentei.org>
date Tue, 21 Apr 2020 07:25:23 +0900
parents 9d053819cbc0
children 5d857faac912
files s4-funcs.sh
diffstat 1 files changed, 13 insertions(+), 15 deletions(-) [+]
line diff
     1.1 --- a/s4-funcs.sh	Mon Apr 20 12:44:57 2020 +0900
     1.2 +++ b/s4-funcs.sh	Tue Apr 21 07:25:23 2020 +0900
     1.3 @@ -17,6 +17,7 @@
     1.4  listentlimit=${LISTENTLIMIT:-30}
     1.5  admin=${ADMIN:-hostmaster@example.org}
     1.6  noreply=${NOREPLY:-noreply@example.org}
     1.7 +noreply_from="${S4NAME:-s4} message notification <$noreply>"
     1.8  templ=${TEMPL:-templ}
     1.9  layout=${LAYOUT:-$templ/default}
    1.10  formdir=${FORMDIR:-$templ/form}
    1.11 @@ -1148,14 +1149,7 @@
    1.12  }
    1.13  smail_queue_flush() {
    1.14    # $1=timelimit
    1.15 -  timelimit=`sq $workdb "SELECT datetime('now', 'localtime', '-1 minutes');"`
    1.16 -    err timelimit="$timelimit" rowid=$rowid
    1.17 -  err r===="$(sq $workdb <<-EOF
    1.18 -	SELECT rowid FROM smailq
    1.19 -	       GROUP BY rcpts, subj
    1.20 -	       HAVING min(time) < '$timelimit';
    1.21 -	EOF
    1.22 -  )"
    1.23 +  timelimit=`query "SELECT datetime('now', 'localtime', '-6 hours');"`
    1.24    rowids=$(sq $workdb <<-EOF
    1.25  	SELECT rowid FROM smailq
    1.26  	       GROUP BY rcpts, subj
    1.27 @@ -1166,12 +1160,12 @@
    1.28      sq $workdb \
    1.29         "SELECT hex(rcpts),hex(subj) FROM smailq WHERE rowid in ($rid)" \
    1.30        | if IFS='|' read hexr hexs; then
    1.31 -      err "hexrcpt=[$hexr] hexsubj=[$hexs]"
    1.32 +      # err "hexrcpt=[$hexr] hexsubj=[$hexs]"
    1.33        rcpt=`echo "$hexr"|unhexize`
    1.34        subj=`echo "$hexs"|unhexize`
    1.35        
    1.36        # err ROWID==$rowid "sql=<<SELECT hex(rcpts),hex(subj) FROM smailq WHERE rowid=$rowid;>>"
    1.37 -      err "rcpt=[$rcpt] subj=[$subj]"
    1.38 +      # err "rcpt=[$rcpt] subj=[$subj]"
    1.39        if sq $workdb <<-EOF | smail "$rcpt" "$subj"
    1.40  	.separator "\n" "------------------\n\n"
    1.41  	SELECT time, text FROM smailq
    1.42 @@ -1192,20 +1186,24 @@
    1.43  }
    1.44  smail_queue() {
    1.45    # $1=Rcpts, $@=subj
    1.46 -  now=`sq $workdb "SELECT datetime('now', 'localtime');"`
    1.47 +  now=`query "SELECT datetime('now', 'localtime');"`
    1.48    if [ $? -eq 0 ]; then
    1.49      rcpts="X'"`echo "$1"|hexize`"'"
    1.50      subj="X'"`echo "$2"|hexize`"'"
    1.51      text="X'"`cat | hexize`"'"
    1.52      err "rcpts=[$rcpts] s=[$subj] t=[$text]"
    1.53 -    mintime=$(tee /tmp/sql  <<-EOF | sq $workdb
    1.54 +    mintime=$(cat  <<-EOF | sq $workdb
    1.55  	CREATE TABLE IF NOT EXISTS smailq(rcpts, subj, text, time);
    1.56  	INSERT INTO smailq VALUES($rcpts, $subj, $text, '$now');
    1.57  	SELECT min(time) FROM smailq WHERE rcpts=$rcpts AND subj=$subj;
    1.58  	EOF
    1.59      )
    1.60 -    err flush_queue=$mintime
    1.61 -    smail_queue_flush
    1.62 +    ## XXX: Adhoc load mitigation
    1.63 +    case "$now" in
    1.64 +      *[01])
    1.65 +	err flush_queue=$mintime
    1.66 +	smail_queue_flush ;;
    1.67 +    esac
    1.68    fi
    1.69  }
    1.70  setviastring() {
    1.71 @@ -2602,7 +2600,7 @@
    1.72  	fromad=`email4groupbyuid "$grp" "$myuid" | sed -e 1q -e 's/[ ,].*//'`
    1.73  	mail_from="$safegc <$fromad>"
    1.74        else
    1.75 -	mail_from="ここには届きません <$noreply>"
    1.76 +	mail_from="$noreply_from"
    1.77        fi
    1.78        MAIL_FROM=$mail_from \
    1.79  	       smail "`email4groupbyuid "$grp" $usel` $user" \