X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fqueue.pm;h=1f2abe3ae4ef3e2b640ca04ce8c1fd0634f64731;hp=8396fc9043c5e15a47f6255ad81bf4899b48ec60;hb=ad7f49821d40ffd099a45acc32ba91e0e211aede;hpb=27bf0365cef058944b8d71379af45d514e0b0c36 diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm index 8396fc904..1f2abe3ae 100644 --- a/FS/FS/queue.pm +++ b/FS/FS/queue.pm @@ -3,7 +3,9 @@ package FS::queue; use strict; use vars qw( @ISA @EXPORT_OK $DEBUG $conf $jobnums); use Exporter; -use FS::UID; +use MIME::Base64; +use Storable qw( nfreeze thaw ); +use FS::UID qw(myconnect); use FS::Conf; use FS::Record qw( qsearch qsearchs dbh ); #use FS::queue; @@ -15,7 +17,6 @@ use FS::cust_svc; @EXPORT_OK = qw( joblisting ); $DEBUG = 0; -#$DEBUG = 1; $FS::UID::callback{'FS::queue'} = sub { $conf = new FS::Conf; @@ -49,17 +50,40 @@ FS::Record. The following fields are currently supported: =over 4 -=item jobnum - primary key +=item jobnum -=item job - fully-qualified subroutine name +Primary key -=item status - job status +=item job -=item statustext - freeform text status message +Fully-qualified subroutine name -=item _date - UNIX timestamp +=item status -=item svcnum - optional link to service (see L) +Job status (new, locked, or failed) + +=item statustext + +Freeform text status message + +=item _date + +UNIX timestamp + +=item svcnum + +Optional link to service (see L). + +=item custnum + +Optional link to customer (see L). + +=item secure + +Secure flag, 'Y' indicates that when using encryption, the job needs to be +run on a machine with the private key. + +=cut =back @@ -69,7 +93,7 @@ FS::Record. The following fields are currently supported: =item new HASHREF -Creates a new job. To add the example to the database, see L<"insert">. +Creates a new job. To add the job 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. @@ -92,7 +116,7 @@ created (see L). #false laziness w/part_export.pm sub insert { - my $self = shift; + my( $self, @args ) = @_; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -105,16 +129,26 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; + my %args = (); + { + no warnings "misc"; + %args = @args; + } + + $self->custnum( $args{'custnum'} ) if $args{'custnum'}; + my $error = $self->SUPER::insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; } - foreach my $arg ( @_ ) { + foreach my $arg ( @args ) { + my $freeze = ref($arg) ? 'Y' : ''; my $queue_arg = new FS::queue_arg ( { 'jobnum' => $self->jobnum, - 'arg' => $arg, + 'frozen' => $freeze, + 'arg' => $freeze ? encode_base64(nfreeze($arg)) : $arg,# always freeze? } ); $error = $queue_arg->insert; if ( $error ) { @@ -224,11 +258,12 @@ Returns a list of the arguments associated with this job. sub args { my $self = shift; - map $_->arg, qsearch( 'queue_arg', - { 'jobnum' => $self->jobnum }, - '', - 'ORDER BY argnum' - ); + map { $_->frozen ? thaw(decode_base64($_->arg)) : $_->arg } + qsearch( 'queue_arg', + { 'jobnum' => $self->jobnum }, + '', + 'ORDER BY argnum' + ); } =item cust_svc @@ -307,6 +342,38 @@ sub depended_delete { } } +=item update_statustext VALUE + +Updates the statustext value of this job to supplied value, in the database. +If there is an error, returns the error, otherwise returns false. + +=cut + +use vars qw($_update_statustext_dbh); +sub update_statustext { + my( $self, $statustext ) = @_; + return '' if $statustext eq $self->statustext; + warn "updating statustext for $self to $statustext" if $DEBUG; + + $_update_statustext_dbh ||= myconnect; + + my $sth = $_update_statustext_dbh->prepare( + 'UPDATE queue set statustext = ? WHERE jobnum = ?' + ) or return $_update_statustext_dbh->errstr; + + $sth->execute($statustext, $self->jobnum) or return $sth->errstr; + $_update_statustext_dbh->commit or die $_update_statustext_dbh->errstr; + $self->statustext($statustext); + ''; + + #my $new = new FS::queue { $self->hash }; + #$new->statustext($statustext); + #my $error = $new->replace($self); + #return $error if $error; + #$self->statustext($statustext); + #''; +} + =back =head1 SUBROUTINES @@ -420,10 +487,6 @@ END =back -=head1 VERSION - -$Id: queue.pm,v 1.18 2004-05-04 18:44:48 ivan Exp $ - =head1 BUGS $jobnums global