4 use vars qw( @ISA @EXPORT_OK );
6 use FS::Record qw( qsearch qsearchs dbh );
11 @ISA = qw(FS::Record);
12 @EXPORT_OK = qw( joblisting );
16 FS::queue - Object methods for queue records
22 $record = new FS::queue \%hash;
23 $record = new FS::queue { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
35 An FS::queue object represents an queued job. FS::queue inherits from
36 FS::Record. The following fields are currently supported:
40 =item jobnum - primary key
42 =item job - fully-qualified subroutine name
44 =item status - job status
46 =item statustext - freeform text status message
48 =item _date - UNIX timestamp
50 =item svcnum - optional link to service (see L<FS::cust_svc>)
60 Creates a new job. To add the example to the database, see L<"insert">.
62 Note that this stores the hash reference, not a distinct copy of the hash it
63 points to. You can ask the object for a copy with the I<hash> method.
67 # the new method can be inherited from FS::Record, if a table method is defined
69 sub table { 'queue'; }
71 =item insert [ ARGUMENT, ARGUMENT... ]
73 Adds this record to the database. If there is an error, returns the error,
74 otherwise returns false.
76 If any arguments are supplied, a queue_arg record for each argument is also
77 created (see L<FS::queue_arg>).
81 #false laziness w/part_export.pm
85 local $SIG{HUP} = 'IGNORE';
86 local $SIG{INT} = 'IGNORE';
87 local $SIG{QUIT} = 'IGNORE';
88 local $SIG{TERM} = 'IGNORE';
89 local $SIG{TSTP} = 'IGNORE';
90 local $SIG{PIPE} = 'IGNORE';
92 my $oldAutoCommit = $FS::UID::AutoCommit;
93 local $FS::UID::AutoCommit = 0;
96 my $error = $self->SUPER::insert;
98 $dbh->rollback if $oldAutoCommit;
102 foreach my $arg ( @_ ) {
103 my $queue_arg = new FS::queue_arg ( {
104 'jobnum' => $self->jobnum,
107 $error = $queue_arg->insert;
109 $dbh->rollback if $oldAutoCommit;
114 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
122 Delete this record from the database. Any corresponding queue_arg records are
130 local $SIG{HUP} = 'IGNORE';
131 local $SIG{INT} = 'IGNORE';
132 local $SIG{QUIT} = 'IGNORE';
133 local $SIG{TERM} = 'IGNORE';
134 local $SIG{TSTP} = 'IGNORE';
135 local $SIG{PIPE} = 'IGNORE';
137 my $oldAutoCommit = $FS::UID::AutoCommit;
138 local $FS::UID::AutoCommit = 0;
141 my @args = qsearch( 'queue_arg', { 'jobnum' => $self->jobnum } );
143 my $error = $self->SUPER::delete;
145 $dbh->rollback if $oldAutoCommit;
149 foreach my $arg ( @args ) {
150 $error = $arg->delete;
152 $dbh->rollback if $oldAutoCommit;
157 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
163 =item replace OLD_RECORD
165 Replaces the OLD_RECORD with this one in the database. If there is an error,
166 returns the error, otherwise returns false.
170 # the replace method can be inherited from FS::Record
174 Checks all fields to make sure this is a valid job. If there is
175 an error, returns the error, otherwise returns false. Called by the insert
183 $self->ut_numbern('jobnum')
184 || $self->ut_anything('job')
185 || $self->ut_numbern('_date')
186 || $self->ut_enum('status',['', qw( new locked failed )])
187 || $self->ut_textn('statustext')
188 || $self->ut_numbern('svcnum')
190 return $error if $error;
192 $error = $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum');
193 $self->svcnum('') if $error;
195 $self->status('new') unless $self->status;
196 $self->_date(time) unless $self->_date;
207 map $_->arg, qsearch( 'queue_arg',
208 { 'jobnum' => $self->jobnum },
216 Returns the FS::cust_svc object associated with this job, if any.
222 qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
225 =item joblisting HASHREF NOACTIONS
230 my($hashref, $noactions) = @_;
235 my @queue = qsearch( 'queue', $hashref );
236 return '' unless scalar(@queue);
238 my $html = FS::CGI::table(). <<END;
240 <TH COLSPAN=2>Job</TH>
245 $html .= '<TH>Account</TH>' unless $hashref->{svcnum};
248 my $p = FS::CGI::popurl(2);
249 foreach my $queue ( sort {
250 $a->getfield('jobnum') <=> $b->getfield('jobnum')
252 my $queue_hashref = $queue->hashref;
253 my $jobnum = $queue->jobnum;
254 my $args = join(' ', $queue->args);
255 my $date = time2str( "%a %b %e %T %Y", $queue->_date );
256 my $status = $queue->status;
257 $status .= ': '. $queue->statustext if $queue->statustext;
258 if ( ! $noactions && $status =~ /^failed/ || $status =~ /^locked/ ) {
260 qq! ( <A HREF="$p/misc/queue.cgi?jobnum=$jobnum&action=new">retry</A> |!.
261 qq! <A HREF="$p/misc/queue.cgi?jobnum=$jobnum&action=del">remove</A> )!;
263 my $cust_svc = $queue->cust_svc;
268 <TD>$queue_hashref->{job}</TD>
274 unless ( $hashref->{svcnum} ) {
277 my $table = $cust_svc->part_svc->svcdb;
278 my $label = ( $cust_svc->label )[1];
279 $account = qq!<A HREF="../view/$table.cgi?!. $queue->svcnum.
284 $html .= "<TD>$account</TD>";
301 $Id: queue.pm,v 1.8 2002-03-23 16:16:00 ivan Exp $
307 L<FS::Record>, schema.html from the base documentation.