user/dev discussion of public-inbox itself
 help / color / mirror / code / 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

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/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://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git