use Net::SSH::ssh_cmd for all job queueing rather than local duplicated ssh subs
[freeside.git] / FS / bin / freeside-queued
index 35728db..56475d0 100644 (file)
@@ -7,14 +7,14 @@ use Fcntl qw(:flock);
 use POSIX qw(setsid);
 use Date::Format;
 use IO::File;
-use FS::UID qw(adminsuidsetup forksuidsetup);
+use FS::UID qw(adminsuidsetup forksuidsetup driver_name);
 use FS::Record qw(qsearchs);
 use FS::queue;
 
 # no autoloading just yet
 use FS::cust_main;
 use FS::svc_acct;
-use Net::SSH;
+use Net::SSH 0.05;
 
 my $pid_file = '/var/run/freeside-queued.pid';
 
@@ -40,7 +40,7 @@ $log_file = "/usr/local/etc/freeside/queuelog.". $FS::UID::datasrc;
 $SIG{__DIE__} = \&_die;
 $SIG{__WARN__} = \&_logmsg;
 
-warn "freesied-queued starting\n";
+warn "freeside-queued starting\n";
 
 while (1) {
 
@@ -48,7 +48,9 @@ while (1) {
     'queue',
     { 'status' => 'new' },
     '',
-    'ORDER BY jobnum FOR UPDATE LIMIT 1'
+    driver_name =~ /^mysql$/i
+      ? 'ORDER BY jobnum LIMIT 1 FOR UPDATE'
+      : 'ORDER BY jobnum FOR UPDATE LIMIT 1'
   ) or do {
     sleep 5;
     next;
@@ -67,6 +69,7 @@ while (1) {
     warn "WARNING: can't fork: $!\n";
     my %hash = $job->hash;
     $hash{'status'} = 'failed';
+    $hash{'statustext'} = "[freeside-queued] can't fork: $!";
     my $ljob = new FS::queue ( \%hash );
     my $error = $ljob->replace($job);
     die $error if $error;
@@ -76,7 +79,7 @@ while (1) {
 
     #get new db handles
     $FS::UID::dbh->{InactiveDestroy} = 1;
-    $FS::svc_acct::icradius_dbh->{InactiveDestroy}
+    $FS::svc_acct::icradius_dbh->{InactiveDestroy} = 1
       if $FS::svc_acct::icradius_dbh;
     forksuidsetup($user);
 
@@ -87,6 +90,7 @@ while (1) {
       warn "job $eval failed";
       my %hash = $ljob->hash;
       $hash{'status'} = 'failed';
+      $hash{'statustext'} = $@;
       my $fjob = new FS::queue( \%hash );
       my $error = $fjob->replace($ljob);
       die $error if $error;