[Bps-public-commit] app-wsgetmail branch add-quiet-mode-for-cron created. 0.08-2-gb261512

BPS Git Server git at git.bestpractical.com
Thu Jul 20 13:53:08 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  b261512c81a904707cee6faabee5fc0479273883 (commit)

- Log -----------------------------------------------------------------
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