5 use FS::Record qw( qsearch qsearchs dbh );
12 FS::queue - Object methods for queue records
18 $record = new FS::queue \%hash;
19 $record = new FS::queue { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::queue object represents an queued job. FS::queue inherits from
32 FS::Record. The following fields are currently supported:
36 =item jobnum - primary key
38 =item job - fully-qualified subroutine name
40 =item status - job status
50 Creates a new job. To add the example to the database, see L<"insert">.
52 Note that this stores the hash reference, not a distinct copy of the hash it
53 points to. You can ask the object for a copy with the I<hash> method.
57 # the new method can be inherited from FS::Record, if a table method is defined
59 sub table { 'queue'; }
61 =item insert [ ARGUMENT, ARGUMENT... ]
63 Adds this record to the database. If there is an error, returns the error,
64 otherwise returns false.
66 If any arguments are supplied, a queue_arg record for each argument is also
67 created (see L<FS::queue_arg>).
74 local $SIG{HUP} = 'IGNORE';
75 local $SIG{INT} = 'IGNORE';
76 local $SIG{QUIT} = 'IGNORE';
77 local $SIG{TERM} = 'IGNORE';
78 local $SIG{TSTP} = 'IGNORE';
79 local $SIG{PIPE} = 'IGNORE';
81 my $oldAutoCommit = $FS::UID::AutoCommit;
82 local $FS::UID::AutoCommit = 0;
85 my $error = $self->SUPER::insert;
87 $dbh->rollback if $oldAutoCommit;
91 foreach my $arg ( @_ ) {
92 my $queue_arg = new FS::queue_arg ( {
93 'jobnum' => $self->jobnum,
96 $error = $queue_arg->insert;
98 $dbh->rollback if $oldAutoCommit;
103 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
111 Delete this record from the database. Any corresponding queue_arg records are
119 local $SIG{HUP} = 'IGNORE';
120 local $SIG{INT} = 'IGNORE';
121 local $SIG{QUIT} = 'IGNORE';
122 local $SIG{TERM} = 'IGNORE';
123 local $SIG{TSTP} = 'IGNORE';
124 local $SIG{PIPE} = 'IGNORE';
126 my $oldAutoCommit = $FS::UID::AutoCommit;
127 local $FS::UID::AutoCommit = 0;
130 my @args = $self->args;
132 my $error = $self->SUPER::delete;
134 $dbh->rollback if $oldAutoCommit;
138 foreach my $arg ( @args ) {
139 $error = $arg->delete;
141 $dbh->rollback if $oldAutoCommit;
146 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
152 =item replace OLD_RECORD
154 Replaces the OLD_RECORD with this one in the database. If there is an error,
155 returns the error, otherwise returns false.
159 # the replace method can be inherited from FS::Record
163 Checks all fields to make sure this is a valid job. If there is
164 an error, returns the error, otherwise returns false. Called by the insert
172 $self->ut_numbern('jobnum')
173 || $self->ut_anything('job')
174 || $self->ut_numbern('_date')
175 || $self->ut_enum('status',['', qw( new locked failed )])
177 return $error if $error;
179 $self->status('new') unless $self->status;
180 $self->_date(time) unless $self->_date;
191 map $_->arg, qsearch( 'queue_arg',
192 { 'jobnum' => $self->jobnum },
202 $Id: queue.pm,v 1.2 2001-09-11 12:24:13 ivan Exp $
208 L<FS::Record>, schema.html from the base documentation.