don't cache timeout errors from gearman
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 14 Jul 2011 08:53:47 +0000 (10:53 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 14 Jul 2011 13:29:11 +0000 (15:29 +0200)
web_ui.pl

index 21673c4..36d00de 100755 (executable)
--- 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;
 }