tsee/p5-Queue-Q — pull request #2 by slanning (2013-02-13 14:47:59+00:00)
Title: commit 6df2ff077d6a49  about unclaim / requeue_busy

__requeue_busy: used by unclaim, requeue_busy_item, and requeue_busy_error

Two problems:
1. passing in the bare hashref $item didn't work,
because the code expected a Queue::Q::ReliableFIFO::Item
so I made that an object when it isn't already
2. the last param to ->call ($error) was undef,
and this seemed to screw up Redis protocol
with an error like "ERR Protocol error: invalid bulk length"
so I passed in empty string in that case (hope that's okay..)

I'm still not sure if this is behaving as expected.
It only unclaims the item the first time,
and seems to behave as if the limit is 1
while $self->requeue_limit defaults to 5 .

Here is a script to demonstrate it
followed by output of the "monitor" command in redis-cli :

use strict;
use warnings;
use Data::Dumper;
use Queue::Q::ReliableFIFO::Redis;
my $q = Queue::Q::ReliableFIFO::Redis->new(
server => $SERVER_NAME,
port => 6379,
queue_name => 'test_unclaim',
);
$q->flush_queue();
$q->enqueue_item({ zero => 0 });
$q->enqueue_item({ one => 1 });
$q->enqueue_item({ two => 2 });
$q->enqueue_item({ three => 3 });
$q->consume(
sub {
my $item = shift;
print "consuming ", Dumper($item);
if ($item->{one} or $item->{two}) {
$q->unclaim($item);
print "unclaimed\n";
}
},
);
__END__

1360764326.695136 [0 10.189.174.199:47857] "MULTI"
1360764326.699180 [0 10.189.174.199:47857] "DEL" "test_unclaim_main"
1360764326.699255 [0 10.189.174.199:47857] "DEL" "test_unclaim_busy"
1360764326.699267 [0 10.189.174.199:47857] "DEL" "test_unclaim_failed"
1360764326.699280 [0 10.189.174.199:47857] "DEL" "test_unclaim_time"
1360764326.699292 [0 10.189.174.199:47857] "EXEC"

1360764326.700529 [0 10.189.174.199:47857] "LPUSH" "test_unclaim_main" "{\"b\":{\"zero\":0},\"t\":1360764326}"

1360764326.701572 [0 10.189.174.199:47857] "LPUSH" "test_unclaim_main" "{\"b\":{\"one\":1},\"t\":1360764326}"

1360764326.702294 [0 10.189.174.199:47857] "LPUSH" "test_unclaim_main" "{\"b\":{\"two\":2},\"t\":1360764326}"

1360764326.703099 [0 10.189.174.199:47857] "LPUSH" "test_unclaim_main" "{\"b\":{\"three\":3},\"t\":1360764326}"

1360764326.704433 [0 10.189.174.199:47857] "RPOPLPUSH" "test_unclaim_main" "test_unclaim_busy"
1360764326.705816 [0 10.189.174.199:47857] "LREM" "test_unclaim_busy" "-1" "{\"b\":{\"zero\":0},\"t\":1360764326}"

1360764326.706599 [0 10.189.174.199:47857] "RPOPLPUSH" "test_unclaim_main" "test_unclaim_busy"
1360764326.708088 [0 10.189.174.199:47857] "SCRIPT" "EXISTS" "53407a61dc2dbe08f5167a0d1f907a37c45ba839"
1360764326.709319 [0 10.189.174.199:47857] "EVALSHA" "53407a61dc2dbe08f5167a0d1f907a37c45ba839" "1" "test_unclaim" "{\"b\":{\"one\":1},\"t\":1360764326}" "5" "1" ""
1360764326.709858 [0 lua] "lrem" "test_unclaim_busy" "1" "{\"b\":{\"one\":1},\"t\":1360764326}"
1360764326.709912 [0 lua] "rpush" "test_unclaim_main" "{\"t\":1360764326,\"rc\":1,\"b\":{\"one\":1}}"
1360764326.710911 [0 10.189.174.199:47857] "LREM" "test_unclaim_busy" "-1" "{\"b\":{\"one\":1},\"t\":1360764326}"

1360764326.711592 [0 10.189.174.199:47857] "RPOPLPUSH" "test_unclaim_main" "test_unclaim_busy"
1360764326.712766 [0 10.189.174.199:47857] "EVALSHA" "53407a61dc2dbe08f5167a0d1f907a37c45ba839" "1" "test_unclaim" "{\"b\":{\"one\":1},\"t\":1360764326}" "5" "1" ""
1360764326.712902 [0 lua] "lrem" "test_unclaim_busy" "1" "{\"b\":{\"one\":1},\"t\":1360764326}"
1360764326.713910 [0 10.189.174.199:47857] "LREM" "test_unclaim_busy" "-1" "{\"t\":1360764326,\"rc\":1,\"b\":{\"one\":1}}"

1360764326.714882 [0 10.189.174.199:47857] "RPOPLPUSH" "test_unclaim_main" "test_unclaim_busy"
1360764326.716029 [0 10.189.174.199:47857] "EVALSHA" "53407a61dc2dbe08f5167a0d1f907a37c45ba839" "1" "test_unclaim" "{\"b\":{\"two\":2},\"t\":1360764326}" "5" "1" ""
1360764326.716164 [0 lua] "lrem" "test_unclaim_busy" "1" "{\"b\":{\"two\":2},\"t\":1360764326}"
1360764326.716209 [0 lua] "rpush" "test_unclaim_main" "{\"t\":1360764326,\"rc\":1,\"b\":{\"two\":2}}"
1360764326.717274 [0 10.189.174.199:47857] "LREM" "test_unclaim_busy" "-1" "{\"b\":{\"two\":2},\"t\":1360764326}"

1360764326.718131 [0 10.189.174.199:47857] "RPOPLPUSH" "test_unclaim_main" "test_unclaim_busy"
1360764326.719433 [0 10.189.174.199:47857] "EVALSHA" "53407a61dc2dbe08f5167a0d1f907a37c45ba839" "1" "test_unclaim" "{\"b\":{\"two\":2},\"t\":1360764326}" "5" "1" ""
1360764326.719585 [0 lua] "lrem" "test_unclaim_busy" "1" "{\"b\":{\"two\":2},\"t\":1360764326}"
1360764326.720614 [0 10.189.174.199:47857] "LREM" "test_unclaim_busy" "-1" "{\"t\":1360764326,\"rc\":1,\"b\":{\"two\":2}}"

1360764326.721583 [0 10.189.174.199:47857] "RPOPLPUSH" "test_unclaim_main" "test_unclaim_busy"
1360764326.722903 [0 10.189.174.199:47857] "LREM" "test_unclaim_busy" "-1" "{\"b\":{\"three\":3},\"t\":1360764326}"

1360764326.723901 [0 10.189.174.199:47857] "RPOPLPUSH" "test_unclaim_main" "test_unclaim_busy"
1360764326.724873 [0 10.189.174.199:47857] "BRPOPLPUSH" "test_unclaim_main" "test_unclaim_busy" "1"
1360764328.002350 [0 10.189.174.199:47857] "RPOPLPUSH" "test_unclaim_main" "test_unclaim_busy"
1360764328.003691 [0 10.189.174.199:47857] "BRPOPLPUSH" "test_unclaim_main" "test_unclaim_busy" "1"
....