Commit ce1f94d2 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Remade previous changes. Introduced no_filter option to Sympa::Spool::next().

parent ac6d33db
......@@ -77,7 +77,7 @@ my $spool_dir = $spool->{directory};
mkdir "$spool_dir/moved", 0755 unless -d "$spool_dir/moved";
while (1) {
my ($message, $handle) = $spool->next;
my ($message, $handle) = $spool->next(no_filter => 1);
if ($message and $handle) {
my $status = process($message);
......
......@@ -88,7 +88,8 @@ sub _create_spool {
}
sub next {
my $self = shift;
my $self = shift;
my %options = @_;
unless ($self->{_metadatas}) {
my $cwd = Cwd::getcwd();
......@@ -131,8 +132,10 @@ sub next {
);
if ($metadata) {
# Skip messages not yet to be delivered.
next unless $metadata->{date} <= time;
unless ($options{no_filter}) {
# Skip messages not yet to be delivered.
next unless $metadata->{date} <= time;
}
my $msg_file = Sympa::Spool::marshal_metadata(
$metadata,
......@@ -430,12 +433,13 @@ L<Sympa::Bulk> implements the spool for bulk sending.
I<Constructor>.
Creates new instance of L<Sympa::Bulk>.
=item next ( )
=item next ( [ no_filter =E<gt> 1 ] )
I<Instance method>.
Gets next packet to process, order is controlled by message priority, then by
packet priority, then by delivery date, then by reception date.
Packets with future delivery date are ignored.
Packets with future delivery date are ignored
(if C<no_filter> option is I<not> set).
Packet will be locked to prevent multiple proccessing of a single packet.
Parameters:
......
......@@ -113,7 +113,6 @@ sub spin {
last if $self->{finish};
}
$self->_init(3);
return $processed;
}
......@@ -264,17 +263,13 @@ source spool class must implement new() and next().
I<Instance method>.
Additional processing
when the spindle class is instantiated ($state is 0), before spin() processes
next object in source spool ($state is 1),
after it processed object ($state is 2),
or when scanning source spool finished or terminated ($state is 3).
next object in source spool ($state is 1) or after it processed object
($state is 2).
If it returns false value, new() will return C<undef> (when $state is 0)
or spin() will terminate processing (when $state is 1).
By default it always returns C<1>.
Note:
$state 3 was added on Sympa 6.2.21b.1.
=item _on_garbage ( $handle )
I<Instance method>, I<overridable>.
......
......@@ -50,19 +50,13 @@ sub _init {
my $self = shift;
my $state = shift;
if ($state == 0) {
# Initialize priority to process.
$self->{_highest_priority} = 'z';
} elsif ($state == 1) {
if ($state == 1) {
Sympa::List::init_list_cache();
# Process grouped notifications.
Sympa::Alarm->instance->flush;
} elsif ($state == 2) {
## Free zombie sendmail process.
#Sympa::Process->instance->reap_child;
} elsif ($state == 3) {
# Initialize priority to process.
$self->{_highest_priority} = 'z';
}
1;
......@@ -99,17 +93,6 @@ sub _twist {
my $self = shift;
my $message = shift;
# Omit messages which may not be processed.
# - z and Z are a null priority, so files stay in queue and are
# processed only if renamed by administrator.
return 0 if lc($message->{priority} || '') eq 'z';
# - Lazily seek highest priority: Messages with lower priority than
# those already found are skipped.
if (length($message->{priority} || '')) {
return 0 if $self->{_highest_priority} lt $message->{priority};
$self->{_highest_priority} = $message->{priority};
}
unless (defined $message->{'message_id'}
and length $message->{'message_id'}) {
$log->syslog('err', 'Message %s has no message ID', $message);
......@@ -435,8 +418,9 @@ message spool again and waits for processing by
L<Sympa::Spindle::ProcessIncoming>.
Order to process messages in source spool are controlled by modification time
of files and delivery date (See L<Sympa::Spool::Automatic>).
Some messages are skipped according to these priorities:
of files and delivery date.
Some messages are skipped according to these priorities
(See L<Sympa::Spool::Automatic>):
=over
......
......@@ -54,8 +54,6 @@ sub _init {
$self->{_loop_info} = {};
$self->{_msgid} = {};
$self->{_msgid_cleanup} = time;
# Initialize priority to process.
$self->{_highest_priority} = 'z';
} elsif ($state == 1) {
Sympa::List::init_list_cache();
# Process grouped notifications
......@@ -70,9 +68,6 @@ sub _init {
} elsif ($state == 2) {
## Free zombie sendmail process.
#Sympa::Process->instance->reap_child;
} elsif ($state == 3) {
# Initialize priority to process.
$self->{_highest_priority} = 'z';
}
1;
......@@ -109,17 +104,6 @@ sub _twist {
my $self = shift;
my $message = shift;
# Omit messages which may not be processed.
# - z and Z are a null priority, so files stay in queue and are
# processed only if renamed by administrator.
return 0 if lc($message->{priority} || '') eq 'z';
# - Lazily seek highest priority: Messages with lower priority than
# those already found are skipped.
if (length($message->{priority} || '')) {
return 0 if $self->{_highest_priority} lt $message->{priority};
$self->{_highest_priority} = $message->{priority};
}
unless (defined $message->{'message_id'}
and length $message->{'message_id'}) {
$log->syslog('err', 'Message %s has no message ID', $message);
......@@ -487,8 +471,9 @@ L<Sympa::Spindle::DoMessage> for ordinal post.
=back
Order to process messages in source spool are controlled by modification time
of files and delivery date (See L<Sympa::Spool::Incoming>).
Some messages are skipped according to these priorities:
of files and delivery date.
Some messages are skipped according to these priorities
(See L<Sympa::Spool::Incoming>):
=over
......
......@@ -135,7 +135,11 @@ sub next {
$metadata = $self->unmarshal($marshalled);
if ($metadata) {
next unless $self->_filter($metadata);
if ($options{no_filter}) {
$self->_filter($metadata);
} else {
next unless $self->_filter($metadata);
}
if ($self->_is_collection) {
$message = $self->_generator->new(%$metadata);
......@@ -602,7 +606,7 @@ Message to be marshalled.
Note:
This method was added on Sympa 6.2.21b.
=item next ( [ no_lock =E<gt> 1 ] )
=item next ( [ no_filter =E<gt> 1 ], [ no_lock =E<gt> 1 ] )
I<Instance method>.
Gets next message to process, order is controlled by name of spool file and
......@@ -613,6 +617,10 @@ Parameters:
=over
=item no_filter =E<gt> 1
Won't skip messages when filter defined by _filter() returns false.
=item no_lock =E<gt> 1
Won't lock messages.
......@@ -992,5 +1000,6 @@ It as the base class appeared on Sympa 6.2.6.
build_glob_pattern(), size(), _glob_pattern() and _store_key()
were introduced on Sympa 6.2.8.
_filter_pre() was introduced on Sympa 6.2.10.
C<no_filter> option of next() was introduced on Sympa 6.2.21b.
=cut
......@@ -68,9 +68,13 @@ See also L<Sympa::Spool/"Public methods">.
=over
=item next ( )
=item next ( [ no_filter =E<gt> 1 ], [ no_lock =E<gt> 1 ] )
Order is controlled by modification time of files and delivery date.
I<Instance method>.
Order is controlled by modification time of files and delivery date, then,
if C<no_filter> is I<not> set,
messages with possiblly higher priority are chosen and
messages with lowest priority (C<z> or C<Z>) are skipped.
=item store ( $message, [ original =E<gt> $original ] )
......
......@@ -41,6 +41,9 @@ sub _directories {
};
}
use constant _filter => 1;
use constant _init => 1;
1;
__END__
......
......@@ -47,6 +47,32 @@ use constant _marshal_keys => [qw(localpart domainpart date PID RAND)];
use constant _marshal_regexp =>
qr{\A([^\s\@]+)(?:\@([\w\.\-]+))?\.(\d+)\.(\w+)(?:,.*)?\z};
sub _filter {
my $self = shift;
my $metadata = shift;
return undef unless $metadata;
# - z and Z are a null priority, so file stay in queue and are
# processed only if renamed by administrator
return 0 if lc($metadata->{priority} || '') eq 'z';
# - Lazily seek highest priority: Messages with lower priority than
# those already found are skipped.
if (length($metadata->{priority} || '')) {
return 0 if $self->{_highest_priority} lt $metadata->{priority};
$self->{_highest_priority} = $metadata->{priority};
}
return 1;
}
sub _init {
my $self = shift;
$self->{_highest_priority} = 'z';
}
sub _load {
my $self = shift;
......@@ -85,9 +111,12 @@ See also L<Sympa::Spool/"Public methods">.
=over
=item next ( )
=item next ( [ no_filter =E<gt> 1 ], [ no_lock =E<gt> 1 ] )
Order is controlled by modification time of file and delivery date.
Order is controlled by modification time of file and delivery date, then,
if C<no_filter> is I<not> set,
messages with possiblly higher priority are chosen and
messages with lowest priority (C<z> or C<Z>) are skipped.
=item store ( $message, [ original =E<gt> $original ] )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment