Improve sending of mailings.

This commit is contained in:
Martin Kamerbeek 2010-05-20 11:59:07 +02:00
parent e7dd066630
commit b7b1811387
3 changed files with 60 additions and 16 deletions

View file

@ -29,6 +29,7 @@ sub crud_definition {
configuration => {
fieldType => 'textarea',
serialize => 1,
defaultValue => {},
},
sendDate => {
fieldType => 'dateTime',
@ -56,6 +57,22 @@ sub getAsset {
return $asset;
}
sub getNextInSendQueue {
my $class = shift;
my $session = shift;
my $it = $class->getAllIterator( $session, {
constraints => [
{ 'state=? or state=?' => [ 'sending', 'scheduled' ] },
{ 'sendDate <= ?' => [ time() ] },
],
orderBy => "state = 'sending' desc, sendDate asc",
limit => 1,
} );
return $it->();
}
sub getStatusLine {
my $self = shift;
my $db = $self->session->db;
@ -124,6 +141,27 @@ sub queueEmails {
return;
}
sub sendQueuedEmails {
my $self = shift;
my $timeLimit = shift;
my $session = $self->session;
return if $self->get('state') eq 'sent';
$self->update( { state => 'sending' } );
my $it = WebGUI::Mailing::Email->getQueued( $session, $self->getId );
while ( my $email = $it->() ) {
return if $timeLimit && time >= $timeLimit;
$email->send;
}
$self->update( { state => 'sent' } );
return 1;
}
sub www_delete {
my $self = shift;
my $session = $self->session;