From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 06A341FA17 for ; Sun, 2 May 2021 06:05:43 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/6] lei: simplify workers_start API Date: Sun, 2 May 2021 06:05:40 +0000 Message-Id: <20210502060542.11598-5-e@80x24.org> In-Reply-To: <20210502060542.11598-1-e@80x24.org> References: <20210502060542.11598-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: In most cases, we just name the worker process based on the command. The only change is for LeiMirror vs "lei add-external --mirror", but I doubt it matters. --- lib/PublicInbox/LEI.pm | 3 ++- lib/PublicInbox/LeiBlob.pm | 2 +- lib/PublicInbox/LeiConvert.pm | 2 +- lib/PublicInbox/LeiImport.pm | 2 +- lib/PublicInbox/LeiLsSearch.pm | 2 +- lib/PublicInbox/LeiMirror.pm | 2 +- lib/PublicInbox/LeiP2q.pm | 2 +- lib/PublicInbox/LeiTag.pm | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 5d701d5e..d5c6bd52 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -542,7 +542,7 @@ sub pkt_op_pair { } sub workers_start { - my ($lei, $wq, $ident, $jobs, $ops) = @_; + my ($lei, $wq, $jobs, $ops) = @_; $ops = { '!' => [ \&fail_handler, $lei ], '|' => [ \&sigpipe_handler, $lei ], @@ -552,6 +552,7 @@ sub workers_start { }; $ops->{''} //= [ $wq->can('_lei_wq_eof') || \&wq_eof, $lei ]; my $end = $lei->pkt_op_pair; + my $ident = $wq->{-wq_ident} // "lei-$lei->{cmd} worker"; $wq->wq_workers_start($ident, $jobs, $lei->oldset, { lei => $lei }); delete $lei->{pkt_op_p}; my $op_c = delete $lei->{pkt_op_c}; diff --git a/lib/PublicInbox/LeiBlob.pm b/lib/PublicInbox/LeiBlob.pm index 0a957358..710430a2 100644 --- a/lib/PublicInbox/LeiBlob.pm +++ b/lib/PublicInbox/LeiBlob.pm @@ -151,7 +151,7 @@ EOM } require PublicInbox::SolverGit; my $self = bless { lxs => $lxs, oid_b => $blob }, __PACKAGE__; - my ($op_c, $ops) = $lei->workers_start($self, 'lei-blob', 1); + my ($op_c, $ops) = $lei->workers_start($self, 1); $lei->{wq1} = $self; $self->wq_io_do('do_solve_blob', []); $self->wq_close(1); diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm index 5b27ec2d..395a80f8 100644 --- a/lib/PublicInbox/LeiConvert.pm +++ b/lib/PublicInbox/LeiConvert.pm @@ -55,7 +55,7 @@ sub lei_convert { # the main "lei convert" method my $devfd = $lei->path_to_fd($ovv->{dst}) // return; $lei->{opt}->{augment} = 1 if $devfd < 0; $self->prepare_inputs($lei, \@inputs) or return; - my ($op_c, $ops) = $lei->workers_start($self, 'lei-convert', 1); + my ($op_c, $ops) = $lei->workers_start($self, 1); $lei->{wq1} = $self; $self->wq_io_do('process_inputs', []); $self->wq_close(1); diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index 394138b4..6a57df47 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -76,7 +76,7 @@ sub lei_import { # the main "lei import" method $lei->{auth}->op_merge($ops, $self) if $lei->{auth}; $self->{-wq_nr_workers} = $j // 1; # locked $lei->{-eml_noisy} = 1; - (my $op_c, $ops) = $lei->workers_start($self, 'lei-import', $j, $ops); + (my $op_c, $ops) = $lei->workers_start($self, $j, $ops); $lei->{wq1} = $self; $lei->{-err_type} = 'non-fatal'; net_merge_all_done($self) unless $lei->{auth}; diff --git a/lib/PublicInbox/LeiLsSearch.pm b/lib/PublicInbox/LeiLsSearch.pm index a00e78fc..6cea6ae8 100644 --- a/lib/PublicInbox/LeiLsSearch.pm +++ b/lib/PublicInbox/LeiLsSearch.pm @@ -72,7 +72,7 @@ sub do_ls_search_long { sub bg_worker ($$$) { my ($lei, $pfx, $json) = @_; my $self = bless { -wq_nr_workers => 1, json => $json }, __PACKAGE__; - my ($op_c, $ops) = $lei->workers_start($self, 'ls-search', 1); + my ($op_c, $ops) = $lei->workers_start($self, 1); $lei->{wq1} = $self; $self->wq_io_do('do_ls_search_long', [], $pfx); $self->wq_close(1); diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index db97b98c..a37e1d5c 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -282,7 +282,7 @@ sub start { require PublicInbox::Inbox; require PublicInbox::Admin; require PublicInbox::InboxWritable; - my ($op, $ops) = $lei->workers_start($self, 'lei_mirror', 1); + my ($op, $ops) = $lei->workers_start($self, 1); $lei->{wq1} = $self; $self->wq_io_do('do_mirror', []); $self->wq_close(1); diff --git a/lib/PublicInbox/LeiP2q.pm b/lib/PublicInbox/LeiP2q.pm index b4893489..f381a31c 100644 --- a/lib/PublicInbox/LeiP2q.pm +++ b/lib/PublicInbox/LeiP2q.pm @@ -188,7 +188,7 @@ sub lei_p2q { # the "lei patch-to-query" entry point } else { $self->{input} = $input; } - my ($op, $ops) = $lei->workers_start($self, 'lei-p2q', 1); + my ($op, $ops) = $lei->workers_start($self, 1); $lei->{wq1} = $self; $self->wq_io_do('do_p2q', []); $self->wq_close(1); diff --git a/lib/PublicInbox/LeiTag.pm b/lib/PublicInbox/LeiTag.pm index 6025c93e..c650e886 100644 --- a/lib/PublicInbox/LeiTag.pm +++ b/lib/PublicInbox/LeiTag.pm @@ -44,7 +44,7 @@ sub lei_tag { # the "lei tag" method $lei->{auth}->op_merge($ops, $self) if $lei->{auth}; $self->{vmd_mod} = $vmd_mod; my $j = $self->{-wq_nr_workers} = 1; # locked for now - (my $op_c, $ops) = $lei->workers_start($self, 'lei-tag', $j, $ops); + (my $op_c, $ops) = $lei->workers_start($self, $j, $ops); $lei->{wq1} = $self; $lei->{-err_type} = 'non-fatal'; net_merge_all_done($self) unless $lei->{auth};