From ef3ad245ae8313abe77b1e6f0d716aee7ef9aefb Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 14 Jul 2011 10:53:47 +0200 Subject: [PATCH] don't cache timeout errors from gearman --- web_ui.pl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/web_ui.pl b/web_ui.pl index 21673c4..36d00de 100755 --- a/web_ui.pl +++ b/web_ui.pl @@ -143,26 +143,25 @@ sub _gearman_redis { warn "# _gearman_redis $key [$timeout s]"; my $redis = Redis->new; - my $ret; + my $json; - if ( $ret = $redis->get($key) ) { + if ( $json = $redis->get($key) ) { warn "redis hit $key\n"; } else { $gearman->timeout($timeout); - $ret = $gearman->req( 'SUBMIT_JOB', $job, '', $params ); - die "no result for $params" unless $ret; - - $redis->set($key => $ret); + $json = $gearman->req( 'SUBMIT_JOB', $job, '', $params ); + die "no result for $params" unless $json; } - $redis->expire($key => 60); # refresh redis key timeout - - $ret = Mojo::JSON->new->decode( $ret ); + my $ret = Mojo::JSON->new->decode( $json ); if ( ! exists $ret->{error} && ref $ret->{columns} ne 'ARRAY' ) { $ret->{error} = 'query run longer than ' . $gearman->timeout . ' s timeout'; } + $redis->set($key => $json); + $redis->expire($key => 60); # refresh redis key timeout + return $ret; } -- 2.20.1