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 wrap: on
line diff
--- a/s4-funcs.sh	Mon Apr 20 12:44:57 2020 +0900
+++ b/s4-funcs.sh	Tue Apr 21 07:25:23 2020 +0900
@@ -17,6 +17,7 @@
 listentlimit=${LISTENTLIMIT:-30}
 admin=${ADMIN:-hostmaster@example.org}
 noreply=${NOREPLY:-noreply@example.org}
+noreply_from="${S4NAME:-s4} message notification <$noreply>"
 templ=${TEMPL:-templ}
 layout=${LAYOUT:-$templ/default}
 formdir=${FORMDIR:-$templ/form}
@@ -1148,14 +1149,7 @@
 }
 smail_queue_flush() {
   # $1=timelimit
-  timelimit=`sq $workdb "SELECT datetime('now', 'localtime', '-1 minutes');"`
-    err timelimit="$timelimit" rowid=$rowid
-  err r===="$(sq $workdb <<-EOF
-	SELECT rowid FROM smailq
-	       GROUP BY rcpts, subj
-	       HAVING min(time) < '$timelimit';
-	EOF
-  )"
+  timelimit=`query "SELECT datetime('now', 'localtime', '-6 hours');"`
   rowids=$(sq $workdb <<-EOF
 	SELECT rowid FROM smailq
 	       GROUP BY rcpts, subj
@@ -1166,12 +1160,12 @@
     sq $workdb \
        "SELECT hex(rcpts),hex(subj) FROM smailq WHERE rowid in ($rid)" \
       | if IFS='|' read hexr hexs; then
-      err "hexrcpt=[$hexr] hexsubj=[$hexs]"
+      # err "hexrcpt=[$hexr] hexsubj=[$hexs]"
       rcpt=`echo "$hexr"|unhexize`
       subj=`echo "$hexs"|unhexize`
       
       # err ROWID==$rowid "sql=<<SELECT hex(rcpts),hex(subj) FROM smailq WHERE rowid=$rowid;>>"
-      err "rcpt=[$rcpt] subj=[$subj]"
+      # err "rcpt=[$rcpt] subj=[$subj]"
       if sq $workdb <<-EOF | smail "$rcpt" "$subj"
 	.separator "\n" "------------------\n\n"
 	SELECT time, text FROM smailq
@@ -1192,20 +1186,24 @@
 }
 smail_queue() {
   # $1=Rcpts, $@=subj
-  now=`sq $workdb "SELECT datetime('now', 'localtime');"`
+  now=`query "SELECT datetime('now', 'localtime');"`
   if [ $? -eq 0 ]; then
     rcpts="X'"`echo "$1"|hexize`"'"
     subj="X'"`echo "$2"|hexize`"'"
     text="X'"`cat | hexize`"'"
     err "rcpts=[$rcpts] s=[$subj] t=[$text]"
-    mintime=$(tee /tmp/sql  <<-EOF | sq $workdb
+    mintime=$(cat  <<-EOF | sq $workdb
 	CREATE TABLE IF NOT EXISTS smailq(rcpts, subj, text, time);
 	INSERT INTO smailq VALUES($rcpts, $subj, $text, '$now');
 	SELECT min(time) FROM smailq WHERE rcpts=$rcpts AND subj=$subj;
 	EOF
     )
-    err flush_queue=$mintime
-    smail_queue_flush
+    ## XXX: Adhoc load mitigation
+    case "$now" in
+      *[01])
+	err flush_queue=$mintime
+	smail_queue_flush ;;
+    esac
   fi
 }
 setviastring() {
@@ -2602,7 +2600,7 @@
 	fromad=`email4groupbyuid "$grp" "$myuid" | sed -e 1q -e 's/[ ,].*//'`
 	mail_from="$safegc <$fromad>"
       else
-	mail_from="ここには届きません <$noreply>"
+	mail_from="$noreply_from"
       fi
       MAIL_FROM=$mail_from \
 	       smail "`email4groupbyuid "$grp" $usel` $user" \

yatex.org