Bug 40934: Add --exclude-code option to process_message_queue.pl
Some libraries want to send digest messages once per day (e.g., at 20:05)
but send all other messages every hour. Currently, this requires listing
almost all letter codes (~85) in the hourly cron job, which is error-prone
and makes it easy to forget notifications at upgrades.
This patch adds a new --exclude-code (-x) option to process_message_queue.pl
that allows excluding specific letter codes from processing, making it much
easier to configure digest scheduling.
Changes:
- Added --exclude-code option to process_message_queue.pl (repeatable)
- Modified C4::Letters::SendQueuedMessages to handle exclude_letter_code parameter
- Supports both scalar and array reference formats
Example usage:
# Send all messages except digests every hour
00 */1 * * * process_message_queue.pl --exclude-code DUEDGST \
--exclude-code PREDUEDGST --exclude-code HOLDDGST \
--exclude-code AUTO_RENEWALS_DGST
# Send all messages including digests once per day
05 20 * * * process_message_queue.pl
Test plan:
1. Apply both patches
2. Run: ktd --shell --run 'prove t/db_dependent/Letters.t'
3. Verify all tests pass (should show 105 tests passing)
4. Create test messages in message_queue with different letter codes:
- Insert messages with codes: DUEDGST, PREDUEDGST, ACQ_NOTIF, HOLD
5. Test single exclusion:
misc/cronjobs/process_message_queue.pl --exclude-code DUEDGST
- Verify DUEDGST messages remain pending
- Verify other messages are processed
6. Test multiple exclusions:
misc/cronjobs/process_message_queue.pl --exclude-code DUEDGST \
--exclude-code PREDUEDGST
- Verify both digest messages remain pending
- Verify non-digest messages are processed
7. Test combined with --code option (should work together):
misc/cronjobs/process_message_queue.pl --code ACQ_NOTIF \
--exclude-code DUEDGST
- Verify only ACQ_NOTIF messages processed (DUEDGST excluded anyway)
8. Test help output:
misc/cronjobs/process_message_queue.pl --help
- Verify --exclude-code option is documented
Sponsored-by: OpenFifth <https://openfifth.co.uk/>
Signed-off-by: Marion Durand <marion.durand@biblibre.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
2bf60ebf21
commit
3430793f07
|
|
@ -1088,6 +1088,13 @@ sub SendQueuedMessages {
|
|||
ref( $params->{letter_code} )
|
||||
&& @{ $params->{letter_code} } ? ( letter_code => $params->{letter_code} ) : (),
|
||||
!ref( $params->{letter_code} ) && $params->{letter_code} ? ( letter_code => $params->{letter_code} ) : (),
|
||||
|
||||
# Check for scalar or array in exclude_letter_code
|
||||
ref( $params->{exclude_letter_code} )
|
||||
&& @{ $params->{exclude_letter_code} } ? ( letter_code => { '-not_in' => $params->{exclude_letter_code} } ) : (),
|
||||
!ref( $params->{exclude_letter_code} )
|
||||
&& $params->{exclude_letter_code} ? ( letter_code => { '!=' => $params->{exclude_letter_code} } ) : (),
|
||||
|
||||
ref( $params->{type} )
|
||||
&& @{ $params->{type} }
|
||||
? ( message_transport_type => $params->{type} )
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ my $verbose = 0;
|
|||
my $where;
|
||||
my @type;
|
||||
my @letter_code;
|
||||
my @exclude_letter_code;
|
||||
my $exit_on_plugin_failure = 0;
|
||||
|
||||
GetOptions(
|
||||
|
|
@ -46,6 +47,7 @@ GetOptions(
|
|||
'v|verbose' => \$verbose,
|
||||
't|type:s' => \@type,
|
||||
'c|code:s' => \@letter_code,
|
||||
'x|exclude-code:s' => \@exclude_letter_code,
|
||||
'w|where:s' => \$where,
|
||||
'e|exit-on-plugin-failure' => \$exit_on_plugin_failure,
|
||||
);
|
||||
|
|
@ -62,6 +64,7 @@ This script has the following parameters :
|
|||
-p --password: password of mail account
|
||||
-t --type: If supplied, only processes this type of message ( email, sms ), repeatable
|
||||
-c --code: If supplied, only processes messages with this letter code, repeatable
|
||||
-x --exclude-code: If supplied, processes all messages except those with this letter code, repeatable
|
||||
-l --limit: The maximum number of messages to process for this run
|
||||
-m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
|
||||
-h --help: this message
|
||||
|
|
@ -86,6 +89,7 @@ try {
|
|||
|
||||
# Remove empty elements, see bug 37075
|
||||
@letter_code = grep { $_ ne q{} } @letter_code;
|
||||
@exclude_letter_code = grep { $_ ne q{} } @exclude_letter_code;
|
||||
|
||||
C4::Letters::SendQueuedMessages(
|
||||
{
|
||||
|
|
@ -96,6 +100,7 @@ C4::Letters::SendQueuedMessages(
|
|||
limit => $limit,
|
||||
type => \@type,
|
||||
letter_code => \@letter_code,
|
||||
exclude_letter_code => \@exclude_letter_code,
|
||||
where => $where,
|
||||
exit_on_plugin_failure => $exit_on_plugin_failure,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue