var $evtype = ''; // any notification...
// this script should only handle EMAIL notifications..
-
+ var $opts;
var $force = false;
function getAuth()
{
if (!$ff->cli) {
die("access denied");
}
- HTML_FlexyFramework::ensureSingle($_SERVER["SCRIPT_NAME"] .'|'. __FILE__, $this);
+ HTML_FlexyFramework::ensureSingle($_SERVER["SCRIPT_NAME"] .'|'. __FILE__ .'|'. (empty($_SERVER['argv'][1]) ? '': $_SERVER['argv'][1]), $this);
return true;
}
$this->generateNotifications();
-
+ $this->assignQueues();
+
//DB_DataObject::debugLevel(1);
$w = DB_DataObject::factory($this->table);
$total = 0;
$w->evtype = $this->evtype;
}
+ $ff = HTML_FlexyFramework::get();
+ if (!empty($ff->Core_Notify['servers'])) {
+ if (!isset($ff->Core_Notify['servers'][gethostname()])) {
+ $this->jerr("Core_Notify['servers']['" . gethostname() ."'] is not set");
+ }
+ $w->server_id = array_search(gethostname(),array_keys($ff->Core_Notify['servers']));
+ }
+
+
+
+
$w->autoJoin();
$w->find();
if ($pushed === false) {
// we only try once to requeue..
+ $this->logecho("REQUEING email for next run, as we have maxed out that domain");
$requeue[] = $p;
continue;
}
+ $this->logecho("PUSHING email, as we have maxed out that domain");
$pushed[] = $p;
foreach($requeue as $p) {
$pp = clone($p);
$p->act_when = $p->sqlValue('NOW + INTERVAL 1 MINUTE');
+ $this->updateServer($p);
$p->update($pp);
}
exit;
}
+ // this sequentially distributes requeued emails.. - to other servers.
+ function updateServer($w)
+ {
+ $ff = HTML_FlexyFramework::get();
+ static $num = 0;
+ if (empty($ff->Core_Notify['servers'])) {
+ return;
+ }
+ $num++;
+ // next server..
+ $w->server_id = $num % count(array_keys($ff->Core_Notify['servers']));
+
+ }
+
+
function generateNotifications()
{
// this should check each module for 'GenerateNotifications.php' class..
}
-
+ function assignQueues()
+ {
+ $ff = HTML_FlexyFramework::get();
+
+ if (empty($ff->Core_Notify['servers'])) {
+ return;
+ }
+
+ $num_servers = count(array_keys($ff->Core_Notify['servers']));
+ $p = DB_DataObject::factory($this->table);
+ // 6 seconds on this machne...
+ $p->query("
+ UPDATE
+ {$this->table}
+ SET
+ server_id = ((@row_number := CASE WHEN @row_number IS NULL THEN 0 ELSE @row_number END +1) % {$num_servers})
+ WHERE
+ sent < '2000-01-01'
+ and
+ event_id = 0
+ and
+ act_start < NOW()
+ and
+ server_id < 0
+ ORDER BY
+ id ASC
+ LIMIT
+ 20000
+ ");
+
+
+ }
function run($id, $email='', $cmdOpts="")
{