- logger('queue: requeue item ' . $id);
- dba::update('queue', ['last' => datetime_convert()], ['id' => $id]);
+ Logger::log('queue: requeue item ' . $id);
+ $queue = DBA::selectFirst('queue', ['retrial'], ['id' => $id]);
+ if (!DBA::isResult($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('now + ' . $delay . ' seconds');
+
+ DBA::update('queue', ['last' => DateTimeFormat::utcNow(), 'retrial' => $retrial + 1, 'next' => $next], ['id' => $id]);