fix sh/dx <call> with sql spot logging
[spider.git] / perl / cluster.pl
index c13d93a1df72b3238e7b23011e96b956434789df..1e10eb518aae676ddbe0d8b85df3825951e52455 100755 (executable)
@@ -123,7 +123,7 @@ use vars qw(@inqueue $systime $starttime $lockfn @outstanding_connects
                        $zombies $root @listeners $lang $myalias @debug $userfn $clusteraddr
                        $clusterport $mycall $decease $is_win $routeroot $me $reqreg $bumpexisting
                        $allowdxby $dbh $dsn $dbuser $dbpass $do_xml $systime_days $systime_daystart
-                       $can_encode $maxconnect_user $maxconnect_node $idle_interval
+                       $can_encode $maxconnect_user $maxconnect_node $idle_interval $log_flush_interval
                   );
 
 @inqueue = ();                                 # the main input queue, an array of hashes
@@ -138,7 +138,9 @@ $maxconnect_user = 3;                       # the maximum no of concurrent connections a user can ha
 $maxconnect_node = 0;                  # Ditto but for nodes. In either case if a new incoming connection
                                                                # takes the no of references in the routing table above these numbers
                                                                # then the connection is refused. This only affects INCOMING connections.
-$idle_interval = 0.100;                        # the wait between invocations of the main idle loop processing.
+$idle_interval = 0.500;                # the wait between invocations of the main idle loop processing.
+$log_flush_interval = 2;               # interval to wait between log flushes
+
 our $ending;                                                              # signal that we are ending;
 
 
@@ -237,7 +239,7 @@ sub new_channel
        $conn->conns($call) if $conn->isa('IntMsg');
 
        # set callbacks
-       $conn->set_error(sub {my $err = shift; error_handler($dxchan, $err)});
+       $conn->set_error(sub {my $err = shift; LogDbg('DXCommand', "Comms error '$err' received for call $dxchan->{call}"); $dxchan->disconnect(1);});
        $conn->set_on_eof(sub {$dxchan->disconnect});
        $conn->set_rproc(sub {my ($conn,$msg) = @_; $dxchan->rec($msg);});
        $dxchan->rec($msg);
@@ -342,7 +344,7 @@ sub idle_loop
        my $timenow = time;
 
        BPQMsg::process();
-       DXChannel::process();
+#      DXChannel::process();
 
        #      $DB::trace = 0;
 
@@ -373,7 +375,7 @@ sub idle_loop
                AGWMsg::process();
                
                Timer::handler();
-
+               DXLog::flushall();
        }
 
        if (defined &Local::process) {
@@ -436,7 +438,7 @@ if (DXSql::init($dsn)) {
        $dbh = $dbh->connect($dsn, $dbuser, $dbpass) if $dbh;
 }
 
-# try to load Encode
+# try to load Encode and Git
 {
        local $^W = 0;
        my $w = $SIG{__DIE__};
@@ -446,6 +448,22 @@ if (DXSql::init($dsn)) {
                import Encode;
                $can_encode = 1;
        }
+       eval { require Git; };
+       unless ($@) {
+               import Git;
+               
+               # determine the real version number
+               my $repo = Git->repository(Directory => "$root/.git");
+               if ($repo) {
+                       my $desc = $repo->command_oneline(['describe', '--long'], STDERR => 0);
+                       if ($desc) {
+                               my ($v, $s, $b, $g) = $desc =~ /^([\d.]+)(?:\.(\d+))?-(\d+)-g([0-9a-f]+)/;
+                               $version = $v;
+                               $build = $b || 0;
+                               $gitversion = "$g\[r]";
+                       }
+               }
+       }
        $SIG{__DIE__} = $w;
 }
 
@@ -602,6 +620,7 @@ $script->run($main::me) if $script;
 #open(DB::OUT, "|tee /tmp/aa");
 
 my $main_loop = Mojo::IOLoop->recurring($idle_interval => \&idle_loop);
+my $log_flush_loop = Mojo::IOLoop->recurring($log_flush_interval => \&DXLog::flushall);
 
 Mojo::IOLoop->start unless Mojo::IOLoop->is_running;