1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # WQ worker for dealing with LeiImport IMAP flags on already-imported messages
6 package PublicInbox::LeiImportKw;
9 use parent qw(PublicInbox::IPC);
13 my $self = bless { -wq_ident => 'lei import_kw worker' }, $cls;
14 my ($op_c, $ops) = $lei->workers_start($self, $self->detect_nproc);
15 $op_c->{ops} = $ops; # for PktOp->event_step
19 sub ipc_atfork_child {
21 my $lei = $self->{lei};
22 $lei->_lei_atfork_child;
23 my $net = delete $lei->{net} // die 'BUG: no lei->{net}';
24 $self->{sto} = $lei->{sto} // die 'BUG: no lei->{sto}';
25 $self->{verbose} = $lei->{opt}->{verbose};
26 $self->{lse} = $self->{sto}->search;
27 $self->{over} = $self->{lse}->over;
28 $self->{-lms_ro} = $net->{-lms_ro} || die 'BUG: net->{-lms_ro} FALSE';
29 $self->SUPER::ipc_atfork_child;
32 sub ck_update_kw { # via wq_io_do
33 my ($self, $url, $uid, $kw) = @_;
34 my $oidbin = $self->{-lms_ro}->imap_oidbin($url, $uid) // return;
35 my @docids = $self->{over}->oidbin_exists($oidbin) or return;
36 $self->{lse}->kw_changed(undef, $kw, \@docids) or return;
38 $self->{lei}->qerr('# '.unpack('H*', $oidbin)." => @$kw\n");
39 $self->{sto}->ipc_do('set_eml_vmd', undef, { kw => $kw }, \@docids);
44 my ($self, $lei) = @$arg;
45 my $wait = $lei->{sto}->ipc_do('done');
46 $lei->can('wq_done_wait')->($arg, $pid);
49 sub _lei_wq_eof { # EOF callback for main lei daemon
51 my $ikw = delete $lei->{ikw} or return $lei->fail;
52 $ikw->wq_wait_old(\&ikw_done_wait, $lei);