unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] lei: share common *done_wait callbacks
@ 2021-04-21 18:36 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-04-21 18:36 UTC (permalink / raw)
  To: meta

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-21 18:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 18:36 [PATCH] lei: share common *done_wait callbacks Eric Wong

unofficial mirror of meta@public-inbox.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://yhetil.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.mail.public-inbox.meta
	nntp://news.public-inbox.org/inbox.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git