[Bps-public-commit] app-wsgetmail branch add-quiet-mode-for-cron created. 0.08-3-g955ed85
BPS Git Server
git at git.bestpractical.com
Mon Aug 28 16:06:04 UTC 2023
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "app-wsgetmail".
The branch, add-quiet-mode-for-cron has been created
at 955ed853b2d0133b38dbae9633dca3c65409b232 (commit)
- Log -----------------------------------------------------------------
commit 955ed853b2d0133b38dbae9633dca3c65409b232
Author: Brian Conry <bconry at bestpractical.com>
Date: Mon Aug 28 10:44:33 2023 -0500
Ignore 503 on folder listing
The MS API sometimes returns 503 to the request for folder details.
This generally seems to be a temporary condition that won't recur on the
next run and there's also no known action to take when it occurs, except
to retry again later.
diff --git a/lib/App/wsgetmail/MS365.pm b/lib/App/wsgetmail/MS365.pm
index d17e30a..182a840 100644
--- a/lib/App/wsgetmail/MS365.pm
+++ b/lib/App/wsgetmail/MS365.pm
@@ -367,6 +367,14 @@ sub get_folder_details {
[@path_parts], { '$filter' => "DisplayName eq '$folder_name'" }
);
unless ($response->is_success) {
+ # Don't ignore 503 response when debugging.
+ if (!$self->debug and $response->code == 503) {
+ # While the exact cause and meaning of this isn't known,
+ # it seems to be a temporary condition, so we'll just
+ # pretend that we got an empty list.
+ return { totalItemCount => 0 };
+ }
+
warn "failed to fetch folder detail " . $response->status_line;
warn "response from server : " . $response->content if $self->debug;
return undef;
commit b261512c81a904707cee6faabee5fc0479273883
Author: Brian Conry <bconry at bestpractical.com>
Date: Wed Jun 28 09:57:13 2023 -0500
Add "quiet" mode for use with cron.
In some organizations wsgetmail is run very frequently out of cron for
many different configuration files. If the output of wsgetmail isn't
discarded that will generate a torrent of emails. If stdout is discared
then emails will only be generated on error, but the error messages
don't identify the configuration that's in use.
This commit adds a "quiet" mode that suppresses the normal messages on
stdout, but preserves them so they can be replayed when there are any
errors in order to identify the configuration file (i.e. account or
folder) that had the error.
diff --git a/bin/wsgetmail b/bin/wsgetmail
index d0bc4b7..64dc7af 100755
--- a/bin/wsgetmail
+++ b/bin/wsgetmail
@@ -59,9 +59,29 @@ use Pod::Usage;
use Getopt::Long;
my ($config_file, $options, $dry_run);
-my ($debug, $help) = (0,0);
+my ($debug, $help, $quiet) = (0,0,0);
+
+{
+ my @buffer;
+
+ sub maybe_print {
+ if($quiet) {
+ push @buffer, @_;
+ }
+ else {
+ print @_;
+ }
+ }
+
+ sub flush_and_die {
+ print STDERR @buffer;
+ @buffer = ();
+ die @_;
+ }
+}
GetOptions('h|help|?' => \$help,
+ "q|quiet" => \$quiet,
"v|verbose|debug" => \$debug,
'dry-run' => \$dry_run,
"c|config|configuration=s" => \$config_file,
@@ -90,13 +110,13 @@ my $lock_file_name = '/tmp/' . join( '.', 'wsgetmail', $config->{username}, $fol
open my $lock_file_fh, '>', $lock_file_name or die "unable to open lock file $lock_file_name ($!)";
if ( !flock $lock_file_fh, LOCK_EX | LOCK_NB ) {
- print "$0 is already running for $config->{username}/$config->{folder} ($!)\n";
+ print "$0 is already running for $config->{username}/$config->{folder} ($!)\n" unless $quiet;
exit;
}
my $getmail = App::wsgetmail->new({config => $config});
-print "\nfetching mail using configuration $config_file\n";
+maybe_print("\nfetching mail using configuration $config_file\n");
my $done_count = 0;
my $error_count = 0;
@@ -111,9 +131,9 @@ while (my $message = $getmail->get_next_message()) {
}
}
-print "\nprocessed $done_count messages\n";
+maybe_print("\nprocessed $done_count messages\n");
-die "there were errors with $error_count messages\n" if $error_count;
+flush_and_die("there were errors with $error_count messages\n") if $error_count;
__END__
@@ -179,6 +199,21 @@ same way by running:
Log additional information about each mail API request and any problems
delivering mail.
+=item --quiet, -q
+
+In "quiet" mode wsgetmail suppresses its normal output on stdout. This ouptut
+identifies the configuration file used and how many messages were processed.
+
+If there are any errors this information is sent to stderr after the error
+messages.
+
+This does not affect the additional logging generated by the verbose/debug
+flag.
+
+The purpose for "quiet" mode is so that, when running wsgetmail multiple times
+on a schedule using multiple configuration files, no output is produced unless
+there are errors, and that output identifies the configuration file used.
+
=item --dry-run
Read mail and deliver it to the configured command, but don't run the
-----------------------------------------------------------------------
hooks/post-receive
--
app-wsgetmail
More information about the Bps-public-commit
mailing list