mirror of
https://github.com/friendica/friendica
synced 2025-05-01 15:04:24 +02:00
We now incrementally calculate the queue delivery time
This commit is contained in:
parent
06bce464ba
commit
d70a20a466
5 changed files with 32 additions and 36 deletions
|
@ -1553,17 +1553,16 @@ class DBStructure
|
|||
"network" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Receiver's network"],
|
||||
"guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Unique GUID of the message"],
|
||||
"created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date, when the message was created"],
|
||||
"last" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
|
||||
"last" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last trial"],
|
||||
"next" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Next retrial date"],
|
||||
"retrial" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Retrial counter"],
|
||||
"content" => ["type" => "mediumtext", "comment" => ""],
|
||||
"batch" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["id"],
|
||||
"cid" => ["cid"],
|
||||
"created" => ["created"],
|
||||
"last" => ["last"],
|
||||
"network" => ["network"],
|
||||
"batch" => ["batch"],
|
||||
"next" => ["next"],
|
||||
]
|
||||
];
|
||||
$database["register"] = [
|
||||
|
|
|
@ -19,7 +19,22 @@ class Queue
|
|||
public static function updateTime($id)
|
||||
{
|
||||
logger('queue: requeue item ' . $id);
|
||||
dba::update('queue', ['last' => DateTimeFormat::utcNow()], ['id' => $id]);
|
||||
$queue = dba::selectFirst('queue', ['retrial'], ['id' => $id]);
|
||||
if (!DBM::is_result($queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$retrial = $queue['retrial'];
|
||||
|
||||
if ($retrial > 14) {
|
||||
self::removeItem($id);
|
||||
}
|
||||
|
||||
// Calculate the delay until the next trial
|
||||
$delay = (($retrial + 3) ** 4) + (rand(1, 30) * ($retrial + 1));
|
||||
$next = DateTimeFormat::utc(date('c', time() + $delay));
|
||||
|
||||
dba::update('queue', ['last' => DateTimeFormat::utcNow(), 'retrial' => $retrial + 1, 'next' => $next], ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,30 +32,12 @@ class Queue
|
|||
$no_dead_check = Config::get('system', 'queue_no_dead_check', false);
|
||||
|
||||
if (!$queue_id) {
|
||||
logger('queue: start');
|
||||
logger('filling queue jobs - start');
|
||||
|
||||
// Handling the pubsubhubbub requests
|
||||
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'PubSubPublish');
|
||||
|
||||
$r = q(
|
||||
"SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
|
||||
INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
|
||||
WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY"
|
||||
);
|
||||
|
||||
if (DBM::is_result($r)) {
|
||||
foreach ($r as $rr) {
|
||||
logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
|
||||
logger('Expired queue data: ' . $rr['content'], LOGGER_DATA);
|
||||
}
|
||||
q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
|
||||
}
|
||||
|
||||
/*
|
||||
* For the first 12 hours we'll try to deliver every 15 minutes
|
||||
* After that, we'll only attempt delivery once per hour.
|
||||
*/
|
||||
$r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");
|
||||
$r = dba::inArray(dba::p("SELECT `id` FROM `queue` WHERE `next` < UTC_TIMESTAMP()"));
|
||||
|
||||
Addon::callHooks('queue_predeliver', $r);
|
||||
|
||||
|
@ -65,6 +47,7 @@ class Queue
|
|||
Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], "Queue", (int) $q_item['id']);
|
||||
}
|
||||
}
|
||||
logger('filling queue jobs - end');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue