Ignore:
Timestamp:
Oct 29, 2009, 10:19:55 PM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
c78d06f
Parents:
7ec65f5
Message:
Use a longer timeout for interactive commands.

Normally, we crank the timeout on HTTP requests way down, in order to
prevent Twitter from hanging barnowl's UI. For user-triggered
requests, however, it is probably slightly more acceptable to hang the
UI for a second or two than to fail just because Twitter is being
slightly slow.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/BarnOwl/Module/Twitter/Handle.pm

    r7ec65f5 r118d800  
    9393
    9494    return $self;
     95}
     96
     97=head2 twitter_command COMMAND ARGS...
     98
     99Call the specified method on $self->{twitter} with an extended
     100timeout. This is intended for interactive commands, with the theory
     101that if the user explicitly requested an action, it is slightly more
     102acceptable to hang the UI for a second or two than to fail just
     103because Twitter is being slightly slow. Polling commands should be
     104called normally, with the default (short) timeout, to prevent
     105background Twitter suckage from hosing the UI normally.
     106
     107=cut
     108
     109sub twitter_command {
     110    my $self = shift;
     111    my $cmd = shift;
     112
     113    eval { $self->{twitter}->{ua}->timeout(5); };
     114    my $result = eval {
     115        $self->{twitter}->$cmd(@_);
     116    };
     117    my $error = $@;
     118    eval { $self->{twitter}->{ua}->timeout(1); };
     119    if ($error) {
     120        die($error);
     121    }
     122    return $result;
    95123}
    96124
     
    218246            die("Twitter: Message over 140 characters long.\n");
    219247        }
    220         if(defined($reply_to)) {
    221             $self->{twitter}->update({
    222                 status => $msg,
    223                 in_reply_to_status_id => $reply_to
    224                });
    225         } else {
    226             $self->{twitter}->update($msg);
    227         }
     248        $self->twitter_command('update', {
     249            status => $msg,
     250            defined($reply_to) ? (in_reply_to_status_id => $reply_to) : ()
     251           });
    228252    }
    229253}
     
    235259    my $msg = shift;
    236260    if(defined $self->{twitter}) {
    237         $self->{twitter}->new_direct_message({
     261        $self->twitter_command('new_direct_message', {
    238262            user => $who,
    239263            text => $msg
     
    272296    my $who = shift;
    273297
    274     my $user = $self->{twitter}->create_friend($who);
     298    my $user = $self->twitter_command('create_friend', $who);
    275299    # returns a string on error
    276300    if (defined $user && !ref $user) {
     
    286310    my $who = shift;
    287311
    288     my $user = $self->{twitter}->destroy_friend($who);
     312    my $user = $self->twitter_command('destroy_friend', $who);
    289313    # returns a string on error
    290314    if (defined $user && !ref $user) {
Note: See TracChangeset for help on using the changeset viewer.