]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiNoteEvent.pm
imap+nntp: share COMPRESS implementation
[public-inbox.git] / lib / PublicInbox / LeiNoteEvent.pm
index 0709754f6d2acc019594e2414b88754fe2bd3392..8581bd9af7f6c9318413bf98cf5846b0adc414cf 100644 (file)
@@ -8,6 +8,7 @@ use strict;
 use v5.10.1;
 use parent qw(PublicInbox::IPC);
 use PublicInbox::DS;
+use Errno qw(ENOENT);
 
 our $to_flush; # { cfgpath => $lei }
 
@@ -26,13 +27,6 @@ sub flush_task { # PublicInbox::DS timer callback
        for my $lei (values %$todo) { flush_lei($lei) }
 }
 
-# sets a timer to flush
-sub note_event_arm_done ($) {
-       my ($lei) = @_;
-       PublicInbox::DS::add_uniq_timer('flush_timer', 5, \&flush_task);
-       $to_flush->{$lei->{cfg}->{'-f'}} //= $lei;
-}
-
 sub eml_event ($$$$) {
        my ($self, $eml, $vmd, $state) = @_;
        my $sto = $self->{lei}->{sto};
@@ -57,10 +51,13 @@ sub eml_event ($$$$) {
        }
 }
 
-sub maildir_event { # via wq_io_do
+sub maildir_event { # via wq_nonblock_do
        my ($self, $fn, $vmd, $state) = @_;
-       my $eml = PublicInbox::InboxWritable::eml_from_path($fn) // return;
-       eml_event($self, $eml, $vmd, $state);
+       if (my $eml = PublicInbox::InboxWritable::eml_from_path($fn)) {
+               eml_event($self, $eml, $vmd, $state);
+       } elsif ($! == ENOENT) {
+               $self->{lms}->clear_src(@{$vmd->{sync_info}});
+       } # else: eml_from_path already warns
 }
 
 sub lei_note_event {
@@ -88,7 +85,9 @@ sub lei_note_event {
                $jobs = 4 if $jobs > 4; # same default as V2Writable
                my ($op_c, $ops) = $lei->workers_start($wq, $jobs);
                $lei->wait_wq_events($op_c, $ops);
-               note_event_arm_done($lei);
+               PublicInbox::DS::add_uniq_timer('flush_timer', 5, \&flush_task);
+               $to_flush->{$lei->{cfg}->{'-f'}} //= $lei;
+               $wq->prepare_nonblock;
                $lei->{lne} = $wq;
        };
        if ($folder =~ /\Amaildir:/i) {
@@ -97,7 +96,7 @@ sub lei_note_event {
                return if index($fl, 'T') >= 0;
                my $kw = PublicInbox::MdirReader::flags2kw($fl);
                my $vmd = { kw => $kw, sync_info => [ $folder, \$bn ] };
-               $self->wq_io_do('maildir_event', [], $fn, $vmd, $state);
+               $self->wq_nonblock_do('maildir_event', $fn, $vmd, $state);
        } # else: TODO: imap
 }
 
@@ -110,9 +109,7 @@ sub ipc_atfork_child {
 }
 
 sub _lei_wq_eof { # EOF callback for main lei daemon
-       my ($lei) = @_;
-       my $lne = delete $lei->{lne} or return $lei->fail;
-       $lei->sto_done_request($lne->{lei_sock});
+       $_[0]->wq_eof('lne');
 }
 
 1;