The fabled twitterqueuehandler

This commit is contained in:
Zach Copley 2009-02-12 14:39:21 -08:00
parent 986068d6e7
commit f8e2ad0677
5 changed files with 76 additions and 4 deletions

View File

@ -231,7 +231,7 @@ function broadcast_twitter($notice)
TWITTER_SERVICE);
// XXX: Not sure WHERE to check whether a notice should go to
// Twitter. Should we even put in the queue if it's not? --Zach
// Twitter. Should we even put in the queue if it shouldn't? --Zach
if (is_twitter_bound($notice, $flink)) {
$fuser = $flink->getForeignUser();

View File

@ -808,7 +808,7 @@ function common_broadcast_notice($notice, $remote=false)
function common_enqueue_notice($notice)
{
foreach (array('jabber', 'omb', 'sms', 'public') as $transport) {
foreach (array('jabber', 'omb', 'sms', 'public', 'twitter') as $transport) {
$qi = new Queue_item();
$qi->notice_id = $notice->id;
$qi->transport = $transport;

View File

@ -23,7 +23,8 @@
DIR=`dirname $0`
for f in xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php \
xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php; do
xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php \
twitterqueuehandler.php; do
echo -n "Starting $f...";
php $DIR/$f

View File

@ -24,7 +24,7 @@ SDIR=`dirname $0`
DIR=`php $SDIR/getpiddir.php`
for f in jabberhandler ombhandler publichandler smshandler \
xmppconfirmhandler xmppdaemon; do
xmppconfirmhandler xmppdaemon twitterhandler ; do
FILES="$DIR/$f.*.pid"
for ff in "$FILES" ; do

71
scripts/twitterqueuehandler.php Executable file
View File

@ -0,0 +1,71 @@
#!/usr/bin/env php
<?php
/*
* Laconica - a distributed open-source microblogging tool
* Copyright (C) 2008, Controlez-Vous, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
print "This script must be run from the command line\n";
exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php');
require_once(INSTALLDIR . '/lib/twitter.php');
require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler');
class TwitterQueueHandler extends QueueHandler
{
function transport()
{
return 'twitter';
}
function start()
{
$this->log(LOG_INFO, "INITIALIZE");
return true;
}
function handle_notice($notice)
{
return broadcast_twitter($notice);
}
function finish()
{
}
}
ini_set("max_execution_time", "0");
ini_set("max_input_time", "0");
set_time_limit(0);
mb_internal_encoding('UTF-8');
$id = ($argc > 1) ? $argv[1] : null;
$handler = new TwitterQueueHandler($id);
$handler->runOnce();