diff options
author | ivan <ivan> | 2002-05-15 13:24:26 +0000 |
---|---|---|
committer | ivan <ivan> | 2002-05-15 13:24:26 +0000 |
commit | eb7c552dd8290d6b33a4e026c5dc21ebf01105cf (patch) | |
tree | f4e307c94039085b55bd2c416e78824cabe52911 /FS | |
parent | ce119821d508611bce8d2c62c3faec237faa6612 (diff) |
queue dependancies
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS.pm | 4 | ||||
-rw-r--r-- | FS/FS/part_export/sqlradius.pm | 34 | ||||
-rw-r--r-- | FS/FS/queue.pm | 37 | ||||
-rw-r--r-- | FS/FS/queue_depend.pm | 120 | ||||
-rw-r--r-- | FS/MANIFEST | 1 | ||||
-rw-r--r-- | FS/bin/freeside-queued | 12 | ||||
-rw-r--r-- | FS/t/queue_depend.t | 5 |
7 files changed, 187 insertions, 26 deletions
@@ -31,7 +31,7 @@ L<FS::CGI> - Non OO-subroutines for the web interface. L<FS::Msgcat> - Message catalog -L<FS::SearchCache> - Message catalog +L<FS::SearchCache> - Search cache L<FS::raddb> - RADIUS dictionary @@ -134,6 +134,8 @@ L<FS::queue> - Job queue L<FS::queue_arg> - Job arguments +L<FS::queue_depend> - Job dependencies + L<FS::msgcat> - Message catalogs =head1 Remote API modules diff --git a/FS/FS/part_export/sqlradius.pm b/FS/FS/part_export/sqlradius.pm index fc680d41b..51a828001 100644 --- a/FS/FS/part_export/sqlradius.pm +++ b/FS/FS/part_export/sqlradius.pm @@ -14,15 +14,16 @@ sub _export_insert { my $method = "radius_$table"; my %attrib = $svc_acct->$method; next unless keys %attrib; - my $error = $self->sqlradius_queue( $svc_acct->svcnum, 'insert', + my $err_or_queue = $self->sqlradius_queue( $svc_acct->svcnum, 'insert', $table, $svc_acct->username, %attrib ); - return $error if $error; + return $err_or_queue unless ref($err_or_queue); } my @groups = $svc_acct->radius_groups; if ( @groups ) { - my $error = $self->sqlradius_queue( $svc_acct->svcnum, 'usergroup_insert', + my $err_or_queue = $self->sqlradius_queue( + $svc_acct->svcnum, 'usergroup_insert', $svc_acct->username, @groups ); - return $error if $error; + return $err_or_queue unless ref($err_or_queue); } ''; } @@ -33,9 +34,9 @@ sub _export_replace { #return "can't (yet) change username with sqlradius" # if $old->username ne $new->username; if ( $old->username ne $new->username ) { - my $error = $self->sqlradius_queue( $new->svcnum, 'rename', + my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'rename', $new->username, $old->username ); - return $error if $error; + return $err_or_queue unless ref($err_or_queue); } foreach my $table (qw(reply check)) { @@ -46,16 +47,16 @@ sub _export_replace { || $new{$_} ne $old{$_} #changed } keys %new ) { - my $error = $self->sqlradius_queue( $new->svcnum, 'insert', + my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'insert', $table, $new->username, %new ); - return $error if $error; + return $err_or_queue unless ref($err_or_queue); } my @del = grep { !exists $new{$_} } keys %old; if ( @del ) { - my $error = $self->sqlradius_queue( $new->svcnum, 'attrib_delete', + my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'attrib_delete', $table, $new->username, @del ); - return $error if $error; + return $err_or_queue unless ref($err_or_queue); } } @@ -72,15 +73,15 @@ sub _export_replace { } if ( @delgroups ) { - my $error = $self->sqlradius_queue( $new->svcnum, 'usergroup_delete', + my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'usergroup_delete', $new->username, @delgroups ); - return $error if $error; + return $err_or_queue unless ref($err_or_queue); } if ( @newgroups ) { - my $error = $self->sqlradius_queue( $new->svcnum, 'usergroup_insert', + my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'usergroup_insert', $new->username, @newgroups ); - return $error if $error; + return $err_or_queue unless ref($err_or_queue); } ''; @@ -88,8 +89,9 @@ sub _export_replace { sub _export_delete { my( $self, $svc_acct ) = (shift, shift); - $self->sqlradius_queue( $svc_acct->svcnum, 'delete', + my $err_or_queue = $self->sqlradius_queue( $svc_acct->svcnum, 'delete', $svc_acct->username ); + ref($err_or_queue) ? '' : $err_or_queue; } sub sqlradius_queue { @@ -103,7 +105,7 @@ sub sqlradius_queue { $self->option('username'), $self->option('password'), @_, - ); + ) or $queue; } sub sqlradius_insert { #subroutine, not method diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm index 5719eff70..c75f75874 100644 --- a/FS/FS/queue.pm +++ b/FS/FS/queue.pm @@ -8,6 +8,7 @@ use FS::Conf; use FS::Record qw( qsearch qsearchs dbh ); #use FS::queue; use FS::queue_arg; +use FS::queue_depend; use FS::cust_svc; @ISA = qw(FS::Record); @@ -144,7 +145,8 @@ sub delete { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my @args = qsearch( 'queue_arg', { 'jobnum' => $self->jobnum } ); + my @del = qsearch( 'queue_arg', { 'jobnum' => $self->jobnum } ); + push @del, qsearch( 'queue_depend', { 'depend_jobnum' => $self->jobnum } ); my $error = $self->SUPER::delete; if ( $error ) { @@ -152,8 +154,8 @@ sub delete { return $error; } - foreach my $arg ( @args ) { - $error = $arg->delete; + foreach my $del ( @del ) { + $error = $del->delete; if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -206,6 +208,8 @@ sub check { =item args +Returns a list of the arguments associated with this job. + =cut sub args { @@ -228,6 +232,31 @@ sub cust_svc { qsearchs('cust_svc', { 'svcnum' => $self->svcnum } ); } +=item depend_insert OTHER_JOBNUM + +Inserts a dependancy for this job. 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. + +=cut + +sub depend_insert { + my($self, $other_jobnum) = @_; + my $queue_depend = new FS::queue_depend ( + 'jobnum' => $self->jobnum, + 'depend_jobnum' => $other_jobnum, + ); + $queue_depend->insert; +} + +=back + +=head1 SUBROUTINES + +=over 4 + =item joblisting HASHREF NOACTIONS =cut @@ -331,7 +360,7 @@ END =head1 VERSION -$Id: queue.pm,v 1.11 2002-04-13 08:51:54 ivan Exp $ +$Id: queue.pm,v 1.12 2002-05-15 13:24:24 ivan Exp $ =head1 BUGS diff --git a/FS/FS/queue_depend.pm b/FS/FS/queue_depend.pm new file mode 100644 index 000000000..4a4e3c55c --- /dev/null +++ b/FS/FS/queue_depend.pm @@ -0,0 +1,120 @@ +package FS::queue_depend; + +use strict; +use vars qw( @ISA ); +use FS::Record qw( qsearch qsearchs ); +use FS::queue; + +@ISA = qw(FS::Record); + +=head1 NAME + +FS::queue_depend - Object methods for queue_depend records + +=head1 SYNOPSIS + + use FS::queue_depend; + + $record = new FS::queue_depend \%hash; + $record = new FS::queue_depend { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::queue_depend object represents an job dependancy. FS::queue_depend +inherits from FS::Record. The following fields are currently supported: + +=over 4 + +=item dependnum - primary key + +=item jobnum - source jobnum (see L<FS::queue>). + +=item depend_jobnum - dependancy jobnum (see L<FS::queue>) + +=back + +The job specified by B<jobnum> depends on the job specified B<depend_jobnum> - +the B<jobnum> job will not be run until the B<depend_jobnum> job has completed +sucessfully (or manually removed). + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new dependancy. To add the dependancy to the database, see +L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I<hash> method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'queue_depend'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +# the insert method can be inherited from FS::Record + +=item delete + +Delete this record from the database. + +=cut + +# the delete method can be inherited from FS::Record + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid dependancy. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +sub check { + my $self = shift; + + $self->ut_numbern('dependnum') + || $self->ut_foreign_key('jobnum', 'queue', 'jobnum') + || $self->ut_foreign_key('depend_jobnum', 'queue', 'jobnum') + ; +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L<FS::queue>, L<FS::Record>, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/MANIFEST b/FS/MANIFEST index 2e72d5af8..a95470bb4 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -78,6 +78,7 @@ FS/raddb.pm FS/radius_usergroup.pm FS/queue.pm FS/queue_arg.pm +FS/queue_depend.pm FS/msgcat.pm FS/cust_tax_exempt.pm t/agent.t diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 49b532ec3..1539a48af 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -59,13 +59,16 @@ while (1) { } $warnkids=0; + my $nodepend = 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. + ' WHERE queue_depend.jobnum = queue.jobnum ) '; + my $job = qsearchs( 'queue', { 'status' => 'new' }, '', driver_name =~ /^mysql$/i - ? 'ORDER BY jobnum LIMIT 1 FOR UPDATE' - : 'ORDER BY jobnum FOR UPDATE LIMIT 1' + ? "$nodepend ORDER BY jobnum LIMIT 1 FOR UPDATE" + : "$nodepend ORDER BY jobnum FOR UPDATE LIMIT 1" ) or do { sleep 5; #connecting to db is expensive next; @@ -94,10 +97,9 @@ while (1) { $kids++; } else { #kid time - #get new db handles + #get new db handle $FS::UID::dbh->{InactiveDestroy} = 1; - $FS::svc_acct::icradius_dbh->{InactiveDestroy} = 1 - if $FS::svc_acct::icradius_dbh; + forksuidsetup($user); #auto-use export classes... diff --git a/FS/t/queue_depend.t b/FS/t/queue_depend.t new file mode 100644 index 000000000..8eaa2cdb3 --- /dev/null +++ b/FS/t/queue_depend.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::queue_depend; +$loaded=1; +print "ok 1\n"; |