Changeset 15557

Show
Ignore:
Timestamp:
07/09/08 13:34:05 (5 years ago)
Author:
daisuke
Message:

- do away with q_retry
- ...and therefore do away with a bunch of methods
- remove interval option from mvalve
- fix tests

Location:
lang/perl/Mvalve/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Mvalve/trunk/lib/Mvalve.pm

    r15555 r15557  
    7878); 
    7979 
    80 has 'interval' => ( 
    81     is => 'rw', 
    82     isa => 'Int', 
    83     required => 1, 
    84     default => 10 
    85 ); 
    86  
    8780has 'timeout' => ( 
    8881    is => 'rw', 
     
    157150    } 
    158151 
    159  
    160152    # otherwise, we need to check if this message is going to be throttled 
    161     trace( "checking if message to $destination should be throttled" ) if MVALVE_TRACE; 
    162     my $is_throttled = 
    163         $self->is_pending( $destination ) || 
    164         ! $self->try_push( key => $destination ) 
    165     ; 
    166  
    167     if ($is_throttled) { 
     153    my $is_pending   = $self->is_pending( $destination ); 
     154    my $is_throttled = ! $self->try_push( key => $destination ); 
     155    trace( "checking if message to $destination should be throttled (pending: $is_pending, throttled: $is_throttled)" ) if MVALVE_TRACE; 
     156 
     157    if ($is_throttled || $is_pending) { 
    168158        trace( "message", $message->id, "is being throttled") if MVALVE_TRACE; 
    169159        $self->defer( $message ); 
     
    185175 
    186176    my $qs          = $self->queue_set; 
    187     my $interval    = $self->interval; 
     177    my $interval    = $self->throttler->{db}->{chain}->{interval}; 
    188178    my $table       = $qs->choose_table('timed'); 
    189179    my $destination = $message->header( DESTINATION_HEADER ); 
     
    248238 
    249239sub is_pending { 
    250     my( $self, $channel_id ) = @_; 
    251  
    252     my $retry_key = [ $channel_id, 'retry' ]; 
     240    my( $self, $destination ) = @_; 
     241 
     242    my $retry_key = [ $destination, 'retry' ]; 
    253243    my $count = $self->state_get($retry_key); 
    254244    return $count ? 1 : 0; 
  • lang/perl/Mvalve/trunk/t/03_extended.t

    r15551 r15557  
    1616 
    1717    $ENV{MEMCACHED_SERVERS} ||= '127.0.0.1:11211'; 
    18     $ENV{MEMCAHCED_NAMESPACE} ||= join('_', __FILE__, $$, {}, rand()); 
     18    $ENV{MEMCACHED_NAMESPACE} ||= join('_', __FILE__, $$, {}, rand()); 
    1919    $ENV{MEMCACHED_SERVERS} = [ 
    2020        split(/\s*,\s*/, $ENV{MEMCACHED_SERVERS}) ]; 
     
    4141            module    => 'Data::Throttler::Memcached', 
    4242            max_items => 1, 
    43             interval  => 10, 
     43            interval  => 2, 
    4444            cache     => { 
    4545                data => $ENV{MEMCACHED_SERVERS}, 
     
    7575        my $message = $mvalve->next; 
    7676        ok( $message, 'first message should not be throttled' ); 
    77         delete $messages{ $message->id }; 
     77        if ($message) { 
     78            delete $messages{ $message->id }; 
     79        } 
    7880 
    7981        $count--; 
     
    8991        my $i = 0; 
    9092        while ($i < $count) { 
    91             my $rv = $mvalve->next_retry; 
    9293            my $message = $mvalve->next; 
    93  
    94             next unless $rv; 
     94            next unless $message; 
    9595 
    9696            ok( delete $messages{ $message->id }, "Deleting a proper (unhandled) message");