]> andersk Git - sql-web.git/blobdiff - cron/checkProcesses.php
more old code
[sql-web.git] / cron / checkProcesses.php
index f04c5a5527d4e080dd3242904693c8c6faa9d644..5d1e5257d0d500858722e84b87988d73633c0f24 100755 (executable)
@@ -3,7 +3,9 @@
 @chdir(dirname(__FILE__).'/../');
 require_once('mitsql.cfg.php');
 require_once('mitsql.lib.php');
-define('MAX_PROC_TIME', 10);
+isOffline() && exit;
+
+define('MAX_PROC_TIME', 100);
 
 $baddbs = $badusers = $bad = array();
 $result = mysql_query('SHOW FULL PROCESSLIST');
@@ -17,25 +19,31 @@ while ($row = mysql_fetch_assoc($result)){
 mysql_free_result($result);
 
 foreach($bad as $badproc) {
+       mysql_query('KILL '.$badproc['Id']);
+    continue;
        $mailtos = $mailnames = array();
        $baddb = mysql_escape_string($badproc['db']);
+       if (empty($baddb)) continue;
        $badtime = $badproc['Time'];
        $badquery = $badproc['Info'];
-       mysql_query('KILL '.$badproc['Id']);
-       if (empty($baddb)) continue;
        $sql = "SELECT User.UserId,User.Name,User.Email
                        FROM `User`
                        NATURAL JOIN DBOwner
                        NATURAL JOIN DB
-                       WHERE DB.Name = '$baddb'";
+                       WHERE DB.Name = '$baddb'
+                         AND User.UL < 10";
        $r = fetchRows(DBSelect($sql),'UserId');
        foreach($r as $addy) {
                $mailtos[] = $addy['Email'];
                $mailnames[] = $addy['Name'];
        }
+       if (empty($mailtos)) {
+               echo "No email found for $baddb\n";
+               continue;
+       }
        $mailto = implode(', ',$mailtos);
        $mailname = implode(', ',$mailnames);
-       $mailsubj = "[sql] Slow Query on $baddb";
+       $mailsubj = "[sql.mit.edu] Slow Query on $baddb";
        $mailbody = "Dear $mailname:
 
 A slow query was found on your database: $baddb
@@ -46,13 +54,17 @@ been appended to this message for your records. Please optimize your
 queries to avoid having your queries killed in the future. If you have any
 questions, please contact sql@mit.edu.
 
-This SQL Service is available at sql.mit.edu.
+The SQL Service
+Email: <sql@mit.edu>
+Web: http://sql.mit.edu/
 
 ---------------------------------------------------------------------------
 
 $badquery";
 
-       mail($mailto,$mailsubj,$mailbody,"From: SQL Service <sql@mit.edu>\r\nBcc: sql@mit.edu\r\n");
+       mysql_query('KILL '.$badproc['Id']);
+       #mail($mailto,$mailsubj,$mailbody,"From: SQL Service <sql@mit.edu>\r\nBcc: sql@mit.edu\r\n");
+    echo $mailbody;
 }
 
 ?>
This page took 0.059295 seconds and 4 git commands to generate.