use job dependancies in FS::part_export::sqlradius.pm
authorivan <ivan>
Wed, 15 May 2002 14:00:33 +0000 (14:00 +0000)
committerivan <ivan>
Wed, 15 May 2002 14:00:33 +0000 (14:00 +0000)
display job dependancies in FS::queue::joblisting

FS/FS/part_export/sqlradius.pm
FS/FS/queue.pm

index 51a8280..b31ec5c 100644 (file)
@@ -1,6 +1,7 @@
 package FS::part_export::sqlradius;
 
 use vars qw(@ISA);
+use FS::Record qw( dbh );
 use FS::part_export;
 
 @ISA = qw(FS::part_export);
@@ -31,12 +32,26 @@ sub _export_insert {
 sub _export_replace {
   my( $self, $new, $old ) = (shift, shift, shift);
 
-  #return "can't (yet) change username with sqlradius"
-  #  if $old->username ne $new->username;
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $jobnum = '';
   if ( $old->username ne $new->username ) {
     my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'rename',
       $new->username, $old->username );
-    return $err_or_queue unless ref($err_or_queue);
+    unless ( ref($err_or_queue) ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $err_or_queue;
+    }
+    $jobnum = $err_or_queue->jobnum;
   }
 
   foreach my $table (qw(reply check)) {
@@ -49,14 +64,34 @@ sub _export_replace {
     ) {
       my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'insert',
         $table, $new->username, %new );
-      return $err_or_queue unless ref($err_or_queue);
+      unless ( ref($err_or_queue) ) {
+        $dbh->rollback if $oldAutoCommit;
+        return $err_or_queue;
+      }
+      if ( $jobnum ) {
+        my $error = $err_or_queue->depend_insert( $jobnum );
+        if ( $error ) {
+          $dbh->rollback if $oldAutoCommit;
+          return $error;
+        }
+      }
     }
 
     my @del = grep { !exists $new{$_} } keys %old;
     if ( @del ) {
       my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'attrib_delete',
         $table, $new->username, @del );
-      return $err_or_queue unless ref($err_or_queue);
+      unless ( ref($err_or_queue) ) {
+        $dbh->rollback if $oldAutoCommit;
+        return $err_or_queue;
+      }
+      if ( $jobnum ) {
+        my $error = $err_or_queue->depend_insert( $jobnum );
+        if ( $error ) {
+          $dbh->rollback if $oldAutoCommit;
+          return $error;
+        }
+      }
     }
   }
 
@@ -75,15 +110,37 @@ sub _export_replace {
   if ( @delgroups ) {
     my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'usergroup_delete',
       $new->username, @delgroups );
-    return $err_or_queue unless ref($err_or_queue);
+    unless ( ref($err_or_queue) ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $err_or_queue;
+    }
+    if ( $jobnum ) {
+      my $error = $err_or_queue->depend_insert( $jobnum );
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return $error;
+      }
+    }
   }
 
   if ( @newgroups ) {
     my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'usergroup_insert',
       $new->username, @newgroups );
-    return $err_or_queue unless ref($err_or_queue);
+    unless ( ref($err_or_queue) ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $err_or_queue;
+    }
+    if ( $jobnum ) {
+      my $error = $err_or_queue->depend_insert( $jobnum );
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return $error;
+      }
+    }
   }
 
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
   '';
 }
 
index c75f758..df92c56 100644 (file)
@@ -232,13 +232,26 @@ sub cust_svc {
   qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
 }
 
+=item queue_depend
+
+Returns the FS::queue_depend objects associated with this job, if any.
+
+=cut
+
+sub queue_depend {
+  my $self = shift;
+  qsearch('queue_depend', { 'jobnum' => $self->jobnum } );
+}
+
+
 =item depend_insert OTHER_JOBNUM
 
-Inserts a dependancy for this job.  If there is an error, returns the error,
-otherwise returns false.
+Inserts a dependancy for this job - it will not be run until the other job
+specified completes.  If there is an error, returns the error, otherwise
+returns false.
 
-When using job dependancies, you should wrap the insertion of jobs in a
-database transaction.  
+When using job dependancies, you should wrap the insertion of all relevant jobs
+in a database transaction.  
 
 =cut
 
@@ -303,6 +316,11 @@ END
     my $date = time2str( "%a %b %e %T %Y", $queue->_date );
     my $status = $queue->status;
     $status .= ': '. $queue->statustext if $queue->statustext;
+    my @queue_depend = $queue->queue_depend;
+    $status .= ' (waiting for '.
+               join(', ', map { $_->other_jobnum } @queue_depend ). 
+               ')'
+      if @queue_depend;
     my $changable = $dangerous
          || ( ! $noactions && $status =~ /^failed/ || $status =~ /^locked/ );
     if ( $changable ) {
@@ -360,7 +378,7 @@ END
 
 =head1 VERSION
 
-$Id: queue.pm,v 1.12 2002-05-15 13:24:24 ivan Exp $
+$Id: queue.pm,v 1.13 2002-05-15 14:00:32 ivan Exp $
 
 =head1 BUGS