From: ivan Date: Wed, 15 May 2002 13:24:26 +0000 (+0000) Subject: queue dependancies X-Git-Tag: freeside_1_4_0_pre13~13 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=eb7c552dd8290d6b33a4e026c5dc21ebf01105cf queue dependancies --- diff --git a/ANNOUCE.1.4.0 b/ANNOUCE.1.4.0 index 63fd3fa95..a3d786508 100644 --- a/ANNOUCE.1.4.0 +++ b/ANNOUCE.1.4.0 @@ -107,22 +107,24 @@ and suspension/unsuspension. -- -added case-insensitive and substring to default search - -full history tables (notification for deleted payments) - -alternate templates (late invoices!) - -new export! (well, almost) - -icradius groups (usergroup table if not radgroupreply & radgroupcheck) - -message catalogs (infrastructure, anyway) & anything which gets sent to a -customer from the signup server should use message catalog - -multi-agent signup server - -signup_server-realtime to run cards immediately - -and signup-alternate.html for free/paid packages on same signup +- New export code! +- Name and company searches: + - now case-insensative + - pulldown for search type +- Email notification for deleted payments +- History tables - complete history of all database changes +- Alternate invoice templates for things like late noitces +- ICRADIUS groups (usergroup table if not radgroupreply & radgroupcheck) +- Signup server + - Error messages in message catalog + - Agent is now selectable (multiple signup servers for different agents + can now run on the same machine) + - signup_server-realtime configuration option to run cards immediately + - signup-alternate.html example for free and pay packages on the same + signup page +- Texas tax + +schema diagram + +-- diff --git a/FS/FS.pm b/FS/FS.pm index 3a9c9f336..963c73548 100644 --- a/FS/FS.pm +++ b/FS/FS.pm @@ -31,7 +31,7 @@ L - Non OO-subroutines for the web interface. L - Message catalog -L - Message catalog +L - Search cache L - RADIUS dictionary @@ -134,6 +134,8 @@ L - Job queue L - Job arguments +L - Job dependencies + L - 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). + +=item depend_jobnum - dependancy jobnum (see L) + +=back + +The job specified by B depends on the job specified B - +the B job will not be run until the B 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 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, L, 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"; diff --git a/Makefile b/Makefile index 68ef79464..be4e9db2a 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,6 @@ INSTALLGROUP = root #not changable yet FREESIDE_CONF = /usr/local/etc/freeside -#VERSION=1.4.0pre12 -#TAG=freeside_1_4_0_pre12 VERSION=1.4.0pre13 TAG=freeside_1_4_0_pre13 #VERSION=1.4.0beta1 diff --git a/README.1.4.0pre13 b/README.1.4.0pre13 new file mode 100644 index 000000000..bd9fb7387 --- /dev/null +++ b/README.1.4.0pre13 @@ -0,0 +1,27 @@ +the following is necessary to upgrade from 1.4.0pre12 to 1.4.0pre13 + +if you're upgrading from before 1.4.0pre13 see README.1.4.0pre12 first! + +if you're upgrading from 1.3.1 follow the instructions in +httemplate/docs/upgrade8.html instead + +---- + +install the FS perl modules and httemplate as per install.html or upgrade8.html + +CREATE TABLE queue_depend ( + dependnum int primary key, + jobnum int not null, + depend_jobnum int not null +); +CREATE INDEX queue_depend1 ON queue_depend ( jobnum ); +CREATE INDEX queue_depend2 ON queue_depend ( depend_jobnum ); + +Run bin/dbdef-create + +Run bin/create-history-tables [username] queue_depend + +Run bin/dbdef-create again + +Restart Apache and freeside-queued + diff --git a/bin/fs-setup b/bin/fs-setup index e05d44531..87921d74e 100755 --- a/bin/fs-setup +++ b/bin/fs-setup @@ -1,6 +1,6 @@ #!/usr/bin/perl -Tw # -# $Id: fs-setup,v 1.90 2002-05-04 15:00:18 ivan Exp $ +# $Id: fs-setup,v 1.91 2002-05-15 13:24:24 ivan Exp $ #to delay loading dbdef until we're ready BEGIN { $FS::Record::setup_hack = 1; } @@ -933,6 +933,17 @@ sub tables_hash_hack { 'index' => [ [ 'jobnum' ] ], }, + 'queue_depend' => { + 'columns' => [ + 'dependnum', 'int', '', '', + 'jobnum', 'int', '', '', + 'depend_jobnum', 'int', '', '', + ], + 'primary_key' => 'dependnum', + 'unique' => [], + 'index' => [ [ 'jobnum' ], [ 'depend_jobnum' ] ], + }, + 'export_svc' => { 'columns' => [ 'exportsvcnum' => 'int', '', '', diff --git a/eg/export_template.pm b/eg/export_template.pm index f2a5a19f7..1d441bda1 100644 --- a/eg/export_template.pm +++ b/eg/export_template.pm @@ -9,8 +9,9 @@ sub rebless { shift; } sub _export_insert { my($self, $svc_something) = (shift, shift); - $self->myexport_queue( $svc_acct->svcnum, 'insert', + $err_or_queue = $self->myexport_queue( $svc_acct->svcnum, 'insert', $svc_something->username, $svc_something->_password ); + ref($err_or_queue) ? '' : $err_or_queue; } sub _export_replace { @@ -18,14 +19,16 @@ sub _export_replace { #return "can't change username with myexport" # if $old->username ne $new->username; #return '' unless $old->_password ne $new->_password; - $self->myexport_queue( $new->svcnum, + $err_or_queue = $self->myexport_queue( $new->svcnum, 'replace', $new->username, $new->_password ); + ref($err_or_queue) ? '' : $err_or_queue; } sub _export_delete { my( $self, $svc_something ) = (shift, shift); - $self->myexport_queue( $svc_acct->svcnum, + $err_or_queue = $self->myexport_queue( $svc_acct->svcnum, 'delete', $svc_something->username ); + ref($err_or_queue) ? '' : $err_or_queue; } #a good idea to queue anything that could fail or take any time @@ -35,7 +38,7 @@ sub myexport_queue { 'svcnum' => $svcnum, 'job' => "FS::part_export::myexport::myexport_$method", }; - $queue->insert( @_ ); + $queue->insert( @_ ) or $queue; } sub myexport_insert { #subroutine, not method diff --git a/httemplate/docs/install.html b/httemplate/docs/install.html index 5c13ac10d..26fa34dd1 100644 --- a/httemplate/docs/install.html +++ b/httemplate/docs/install.html @@ -186,7 +186,7 @@ $ bin/fs-setup username $ su freeside $ bin/populate-msgcat username -
  • freeside-queued was installed with the Perl modules. Start it now and ensure that is run upon system startup. +
  • freeside-queued was installed with the Perl modules. Start it now and ensure that is run upon system startup (Do this manually, or, edit the top-level Makefile, replacing INIT_FILE with the appropriate location on your system, and run make install-init.
  • Now proceed to the initial administration of your installation. diff --git a/httemplate/docs/schema.dia b/httemplate/docs/schema.dia index 148c1dfbc..c22a470e0 100644 Binary files a/httemplate/docs/schema.dia and b/httemplate/docs/schema.dia differ diff --git a/httemplate/docs/schema.html b/httemplate/docs/schema.html index 3f627448f..2b8b3a132 100644 --- a/httemplate/docs/schema.html +++ b/httemplate/docs/schema.html @@ -401,6 +401,12 @@
  • jobnum - job
  • arg - argument +
  • queue_depend - job dependancies +
      +
    • dependnum - primary key +
    • jobnum - source jobnum +
    • depend_jobnum - dependancy jobnum +
  • radius_usergroup - Link users to RADIUS groups.
    • usergroupnum - primary key diff --git a/httemplate/docs/schema.png b/httemplate/docs/schema.png index b3f00375e..ba22f59c2 100644 Binary files a/httemplate/docs/schema.png and b/httemplate/docs/schema.png differ diff --git a/httemplate/docs/upgrade8.html b/httemplate/docs/upgrade8.html index 97758fdb2..e6184df14 100644 --- a/httemplate/docs/upgrade8.html +++ b/httemplate/docs/upgrade8.html @@ -120,6 +120,14 @@ CREATE TABLE queue_arg ( ); CREATE INDEX queue_arg1 ON queue_arg ( jobnum ); +CREATE TABLE queue_depend ( + dependnum int primary key, + jobnum int not null, + depend_jobnum int not null +); +CREATE INDEX queue_depend1 ON queue_depend ( jobnum ); +CREATE INDEX queue_depend2 ON queue_depend ( depend_jobnum ); + CREATE TABLE part_pop_local ( localnum int primary key, popnum int not null,