configure timeout and display error about it
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 7 Apr 2011 20:37:34 +0000 (22:37 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 7 Apr 2011 20:37:34 +0000 (22:37 +0200)
templates/gnuplot.html.ep
web_ui.pl

index 6ec7b4b..e4544e9 100644 (file)
@@ -2,6 +2,7 @@
 <%= form_for gnuplot => begin %>
  <%= text_area 'sql', cols => 80, rows => 5 %>
  <br>with <%= select_field with => [qw(dots points steps lines)], 'dots' %>
+ timeout <%= text_field 'timeout', value => 5, style => 'width: 2em' %>s
  <%= submit_button 'execute' %>
  <%= check_box 'include_gnuplot' => 1, title => 'include gnuplot dump' %>
 <% end %>
index 2768f27..21553c2 100755 (executable)
--- a/web_ui.pl
+++ b/web_ui.pl
@@ -85,11 +85,14 @@ get '/gnuplot' => sub {
        $sql =~ s/\s+(from|where|order|limit|join)/\n$1/gs;
        $self->param( sql => $sql );
 
+       $gearman->timeout( $self->param('timeout') );
        my $ret = $gearman->req( 'SUBMIT_JOB', 'Store_sql', '', $sql );
        die "no result for $sql" unless $ret;
 
        $ret = Mojo::JSON->new->decode( $ret );
 
+       $ret->{error} = 'query run longer than ' . $gearman->timeout . ' s timeout' unless ref $ret->{columns} eq 'ARRAY';
+
        return $self->render('gnuplot', sql => $sql, img => '', gnuplot => $ret->{error} )
                if exists $ret->{error};