3 function update_queue_time($id) {
4 logger('queue: requeue item ' . $id);
5 q("UPDATE `queue` SET `last` = '%s' WHERE `id` = %d",
6 dbesc(datetime_convert()),
11 function remove_queue_item($id) {
12 logger('queue: remove queue item ' . $id);
13 q("DELETE FROM `queue` WHERE `id` = %d",
19 * @brief Checks if the communication with a given contact had problems recently
21 * @param int $cid Contact id
23 * @return bool The communication with this contact has currently problems
25 function was_recently_delayed($cid) {
28 // Are there queue entries that were recently added?
29 $r = q("SELECT `id` FROM `queue` WHERE `cid` = %d
30 AND `last` > UTC_TIMESTAMP() - INTERVAL 15 MINUTE LIMIT 1",
34 $was_delayed = dbm::is_result($r);
36 // We set "term-date" to a current date if the communication has problems.
37 // If the communication works again we reset this value.
39 $r = q("SELECT `term-date` FROM `contact` WHERE `id` = %d AND `term-date` <= '1000-01-01' LIMIT 1",
42 $was_delayed = !dbm::is_result($r);
49 function add_to_queue($cid,$network,$msg,$batch = false) {
51 $max_queue = get_config('system','max_contact_queue');
55 $batch_queue = get_config('system','max_batch_queue');
59 $r = q("SELECT COUNT(*) AS `total` FROM `queue` INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
60 WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ",
63 if (dbm::is_result($r)) {
64 if($batch && ($r[0]['total'] > $batch_queue)) {
65 logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message');
68 elseif((! $batch) && ($r[0]['total'] > $max_queue)) {
69 logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message');
74 q("INSERT INTO `queue` ( `cid`, `network`, `created`, `last`, `content`, `batch`)
75 VALUES ( %d, '%s', '%s', '%s', '%s', %d) ",
78 dbesc(datetime_convert()),
79 dbesc(datetime_convert()),
81 intval(($batch) ? 1: 0)