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 E744C1F5AE for ; Wed, 21 Apr 2021 18:36:10 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei: share common *done_wait callbacks Date: Wed, 21 Apr 2021 18:36:10 +0000 Message-Id: <20210421183610.29659-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Code is the enemy, and there's no need to duplicate things, here. There may be further opportunities along these lines to further deduplicate things... --- lib/PublicInbox/LEI.pm | 7 +++++++ lib/PublicInbox/LeiBlob.pm | 9 +-------- lib/PublicInbox/LeiImport.pm | 9 +-------- lib/PublicInbox/LeiTag.pm | 9 +-------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 8fa89944..2e1aa246 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -1211,4 +1211,11 @@ sub DESTROY { $? = $err if $err; # preserve ->fail or ->x_it code } +sub wq_done_wait { # dwaitpid callback + my ($arg, $pid) = @_; + my ($wq, $lei, $e) = @$arg; + $? and $lei->child_error($?, $e ? "$e errors during $lei->{cmd}" : ()); + $lei->dclose; +} + 1; diff --git a/lib/PublicInbox/LeiBlob.pm b/lib/PublicInbox/LeiBlob.pm index ad885306..e4cd4cca 100644 --- a/lib/PublicInbox/LeiBlob.pm +++ b/lib/PublicInbox/LeiBlob.pm @@ -10,17 +10,10 @@ use parent qw(PublicInbox::IPC); use PublicInbox::Spawn qw(spawn popen_rd which); use PublicInbox::DS; -sub sol_done_wait { # dwaitpid callback - my ($arg, $pid) = @_; - my (undef, $lei) = @$arg; - $lei->child_error($?) if $?; - $lei->dclose; -} - sub sol_done { # EOF callback for main daemon my ($lei) = @_; my $sol = delete $lei->{sol} // return $lei->dclose; # already failed - $sol->wq_wait_old(\&sol_done_wait, $lei); + $sol->wq_wait_old($lei->can('wq_done_wait'), $lei); } sub get_git_dir ($$) { diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index d33143ef..16271603 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -35,17 +35,10 @@ sub input_net_cb { # imap_each, nntp_each cb input_eml_cb($self, $eml, $self->{-import_kw} ? { kw => $kw } : undef); } -sub import_done_wait { # dwaitpid callback - my ($arg, $pid) = @_; - my ($imp, $lei) = @$arg; - $lei->child_error($?, 'non-fatal errors during import') if $?; - $lei->dclose; -} - sub import_done { # EOF callback for main daemon my ($lei) = @_; my $imp = delete $lei->{imp} // return $lei->fail('BUG: {imp} gone'); - $imp->wq_wait_old(\&import_done_wait, $lei); + $imp->wq_wait_old($lei->can('wq_done_wait'), $lei, 'non-fatal'); } sub net_merge_complete { # callback used by LeiAuth diff --git a/lib/PublicInbox/LeiTag.pm b/lib/PublicInbox/LeiTag.pm index 1dfc841d..f019202f 100644 --- a/lib/PublicInbox/LeiTag.pm +++ b/lib/PublicInbox/LeiTag.pm @@ -71,17 +71,10 @@ sub input_eml_cb { # used by PublicInbox::LeiInput::input_fh sub input_mbox_cb { input_eml_cb($_[1], $_[0]) } -sub tag_done_wait { # dwaitpid callback - my ($arg, $pid) = @_; - my ($tag, $lei) = @$arg; - $lei->child_error($?, 'non-fatal errors during tag') if $?; - $lei->dclose; -} - sub tag_done { # EOF callback for main daemon my ($lei) = @_; my $tag = delete $lei->{tag} or return; - $tag->wq_wait_old(\&tag_done_wait, $lei); + $tag->wq_wait_old($lei->can('wq_done_wait'), $lei, 'non-fatal'); } sub net_merge_complete { # callback used by LeiAuth