From d6578733be494471a5f127b97e1035db3bde7ed2 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 4 Apr 2019 14:14:55 +0000 Subject: [PATCH 1/2] Replace the "Queue" mechanism with deferred workers --- diaspora/diaspora.php | 5 +++-- pumpio/pumpio.php | 8 ++++---- twitter/twitter.php | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/diaspora/diaspora.php b/diaspora/diaspora.php index 88630fe0a..d8c634358 100644 --- a/diaspora/diaspora.php +++ b/diaspora/diaspora.php @@ -18,6 +18,7 @@ use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Database\DBA; use Friendica\Model\Queue; +use Friendica\Core\Worker; function diaspora_install() { @@ -402,8 +403,8 @@ function diaspora_send(App $a, array &$b) $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $body]); - Queue::add($a->contact, Protocol::DIASPORA2, $s); - notice(L10n::t('Diaspora post failed. Queued for retry.').EOL); + Worker::defer(); + notice(L10n::t('Diaspora post failed. Deferred for retry.').EOL); } } } diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 319c109ad..b6716ebc6 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -617,8 +617,8 @@ function pumpio_send(App $a, array &$b) $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $params]); - Queue::add($a->contact, Protocol::PUMPIO, $s); - notice(L10n::t('Pump.io post failed. Queued for retry.').EOL); + Worker::defer(); + notice(L10n::t('Pump.io post failed. Deferred for retry.').EOL); } } } @@ -694,8 +694,8 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") $s = serialize(['url' => $url, 'item' => $orig_post["id"], 'post' => $params]); - Queue::add($a->contact, Protocol::PUMPIO, $s); - notice(L10n::t('Pump.io like failed. Queued for retry.').EOL); + Worker::defer(); + notice(L10n::t('Pump.io like failed. Deferred for retry.').EOL); } } diff --git a/twitter/twitter.php b/twitter/twitter.php index 2d331a7d6..74ebf5fdd 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -692,8 +692,8 @@ function twitter_post_hook(App $a, array &$b) $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $post]); - Queue::add($a->contact, Protocol::TWITTER, $s); - notice(L10n::t('Twitter post failed. Queued for retry.') . EOL); + Worker::defer(); + notice(L10n::t('Twitter post failed. Deferred for retry.') . EOL); } elseif ($iscomment) { Logger::log('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']); Item::update(['extid' => "twitter::" . $result->id_str], ['id' => $b['id']]); From b1b58150553cc9fb604e8b5da759a56703b5ffdd Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 4 Apr 2019 14:22:15 +0000 Subject: [PATCH 2/2] Removed useless stuff --- diaspora/diaspora.php | 7 ------- pumpio/pumpio.php | 18 ------------------ twitter/twitter.php | 9 --------- 3 files changed, 34 deletions(-) diff --git a/diaspora/diaspora.php b/diaspora/diaspora.php index d8c634358..cf272a27b 100644 --- a/diaspora/diaspora.php +++ b/diaspora/diaspora.php @@ -397,14 +397,7 @@ function diaspora_send(App $a, array &$b) Logger::log('diaspora_send: requeueing '.$b['uid'], Logger::DEBUG); - $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']); - if (count($r)) - $a->contact = $r[0]["id"]; - - $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $body]); - Worker::defer(); - notice(L10n::t('Diaspora post failed. Deferred for retry.').EOL); } } } diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index b6716ebc6..6fa2ebf76 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -609,16 +609,7 @@ function pumpio_send(App $a, array &$b) } } else { Logger::log('pumpio_send '.$username.': '.$url.' general error: ' . print_r($user, true)); - - $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']); - if (DBA::isResult($r)) { - $a->contact = $r[0]["id"]; - } - - $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $params]); - Worker::defer(); - notice(L10n::t('Pump.io post failed. Deferred for retry.').EOL); } } } @@ -686,16 +677,7 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") Logger::log('pumpio_action '.$username.' '.$action.': success '.$uri); } else { Logger::log('pumpio_action '.$username.' '.$action.': general error: '.$uri.' '.print_r($user, true)); - - $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $uid); - if (DBA::isResult($r)) { - $a->contact = $r[0]["id"]; - } - - $s = serialize(['url' => $url, 'item' => $orig_post["id"], 'post' => $params]); - Worker::defer(); - notice(L10n::t('Pump.io like failed. Deferred for retry.').EOL); } } diff --git a/twitter/twitter.php b/twitter/twitter.php index 74ebf5fdd..fbe30ce0a 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -684,16 +684,7 @@ function twitter_post_hook(App $a, array &$b) if (!empty($result->errors)) { Logger::log('Send to Twitter failed: "' . print_r($result->errors, true) . '"'); - - $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($b['uid'])); - if (DBA::isResult($r)) { - $a->contact = $r[0]["id"]; - } - - $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $post]); - Worker::defer(); - notice(L10n::t('Twitter post failed. Deferred for retry.') . EOL); } elseif ($iscomment) { Logger::log('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']); Item::update(['extid' => "twitter::" . $result->id_str], ['id' => $b['id']]);