correct timeout handling
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 7 Apr 2011 20:51:18 +0000 (20:51 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 7 Apr 2011 20:51:18 +0000 (20:51 +0000)
templates/gnuplot.html.ep
web_ui.pl

index e4544e9..65435a4 100644 (file)
@@ -2,7 +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
+ timeout <%= input_tag 'timeout', type => 'number', style => 'width: 3em' %>s
  <%= submit_button 'execute' %>
  <%= check_box 'include_gnuplot' => 1, title => 'include gnuplot dump' %>
 <% end %>
index 21553c2..59752b9 100755 (executable)
--- a/web_ui.pl
+++ b/web_ui.pl
@@ -79,13 +79,20 @@ get '/gnuplot' => sub {
        my $self = shift;
 
        my $sql = $self->param('sql');
+
+       if ( my $timeout = $self->param('timeout') ) {
+               warn "set timout to $timeout";
+               $gearman->timeout( $timeout );
+       } else {
+               $self->param( timeout => $gearman->timeout );
+       }
+
        return $self->render('gnuplot', img => '', gnuplot => '') unless $sql;
 
        # re-format SQL
        $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;