From a19484a09c3263a68533887008c6ffc971e2f902 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 29 Dec 2023 10:11:25 +0200 Subject: [PATCH] mass email max per batch --- .../metadata/entityDefs/ScheduledJob.json | 2 +- .../Crm/Tools/MassEmail/SendingProcessor.php | 15 +++++++++++---- application/Espo/Resources/defaults/config.php | 1 + .../Espo/Resources/defaults/systemConfig.php | 1 + .../Espo/Resources/i18n/en_US/Settings.json | 1 + .../layouts/Settings/outboundEmails.json | 5 +++-- .../Resources/metadata/entityDefs/Settings.json | 4 ++++ install/core/afterInstall/records.php | 4 ++-- 8 files changed, 24 insertions(+), 9 deletions(-) diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/ScheduledJob.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/ScheduledJob.json index 6edfa9c02b..57474f81c2 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/ScheduledJob.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/ScheduledJob.json @@ -1,6 +1,6 @@ { "jobSchedulingMap": { - "ProcessMassEmail": "15 * * * *", + "ProcessMassEmail": "10,30,50 * * * *", "ControlKnowledgeBaseArticleStatus": "10 1 * * *" }, "jobs": { diff --git a/application/Espo/Modules/Crm/Tools/MassEmail/SendingProcessor.php b/application/Espo/Modules/Crm/Tools/MassEmail/SendingProcessor.php index 9956b58832..a343bf97ab 100644 --- a/application/Espo/Modules/Crm/Tools/MassEmail/SendingProcessor.php +++ b/application/Espo/Modules/Crm/Tools/MassEmail/SendingProcessor.php @@ -108,7 +108,8 @@ class SendingProcessor */ public function process(MassEmail $massEmail, bool $isTest = false): void { - $maxBatchSize = $this->config->get('massEmailMaxPerHourCount', self::MAX_PER_HOUR_COUNT); + $hourMaxSize = $this->config->get('massEmailMaxPerHourCount', self::MAX_PER_HOUR_COUNT); + $batchMaxSize = $this->config->get('massEmailMaxPerBatchCount'); if (!$isTest) { $threshold = new DateTime(); @@ -122,11 +123,17 @@ class SendingProcessor ]) ->count(); - if ($sentLastHourCount >= $maxBatchSize) { + if ($sentLastHourCount >= $hourMaxSize) { return; } - $maxBatchSize = $maxBatchSize - $sentLastHourCount; + $hourMaxSize = $hourMaxSize - $sentLastHourCount; + } + + $maxSize = $hourMaxSize; + + if ($batchMaxSize) { + $maxSize = min($batchMaxSize, $maxSize); } $queueItemList = $this->entityManager @@ -136,7 +143,7 @@ class SendingProcessor 'massEmailId' => $massEmail->getId(), 'isTest' => $isTest, ]) - ->limit(0, $maxBatchSize) + ->limit(0, $maxSize) ->find(); $templateId = $massEmail->getEmailTemplateId(); diff --git a/application/Espo/Resources/defaults/config.php b/application/Espo/Resources/defaults/config.php index caea07c57a..7e14d3abe7 100644 --- a/application/Espo/Resources/defaults/config.php +++ b/application/Espo/Resources/defaults/config.php @@ -187,6 +187,7 @@ return [ 'theme' => 'Violet', 'themeParams' => (object) ['navbar' => 'side'], 'massEmailMaxPerHourCount' => 100, + 'massEmailMaxPerBatchCount' => null, 'massEmailVerp' => false, 'personalEmailMaxPortionSize' => 50, 'inboundEmailMaxPortionSize' => 50, diff --git a/application/Espo/Resources/defaults/systemConfig.php b/application/Espo/Resources/defaults/systemConfig.php index c210f4ca45..01ba73c038 100644 --- a/application/Espo/Resources/defaults/systemConfig.php +++ b/application/Espo/Resources/defaults/systemConfig.php @@ -161,6 +161,7 @@ return [ 'ldapUserObjectClass', 'maxEmailAccountCount', 'massEmailMaxPerHourCount', + 'massEmailMaxPerBatchCount', 'massEmailSiteUrl', 'personalEmailMaxPortionSize', 'inboundEmailMaxPortionSize', diff --git a/application/Espo/Resources/i18n/en_US/Settings.json b/application/Espo/Resources/i18n/en_US/Settings.json index f41d66d4ea..7253f4a9d5 100644 --- a/application/Espo/Resources/i18n/en_US/Settings.json +++ b/application/Espo/Resources/i18n/en_US/Settings.json @@ -81,6 +81,7 @@ "attachmentUploadChunkSize": "Upload Chunk Size (Mb)", "emailMessageMaxSize": "Email Max Size (Mb)", "massEmailMaxPerHourCount": "Max number of emails sent per hour", + "massEmailMaxPerBatchCount": "Max number of emails sent per batch", "personalEmailMaxPortionSize": "Max email portion size for personal account fetching", "inboundEmailMaxPortionSize": "Max email portion size for group account fetching", "maxEmailAccountCount": "Max number of personal email accounts per user", diff --git a/application/Espo/Resources/layouts/Settings/outboundEmails.json b/application/Espo/Resources/layouts/Settings/outboundEmails.json index e7df176526..af187e123b 100644 --- a/application/Espo/Resources/layouts/Settings/outboundEmails.json +++ b/application/Espo/Resources/layouts/Settings/outboundEmails.json @@ -19,8 +19,9 @@ { "label": "Mass Email", "rows": [ - [{"name": "massEmailMaxPerHourCount"}, {"name": "massEmailDisableMandatoryOptOutLink"}], - [{"name": "massEmailOpenTracking"}, {"name": "massEmailVerp"}] + [{"name": "massEmailMaxPerHourCount"}, {"name": "massEmailMaxPerBatchCount"}], + [{"name": "massEmailOpenTracking"}, {"name": "massEmailVerp"}], + [{"name": "massEmailDisableMandatoryOptOutLink"}, false] ] } ] diff --git a/application/Espo/Resources/metadata/entityDefs/Settings.json b/application/Espo/Resources/metadata/entityDefs/Settings.json index a091576418..2092481011 100644 --- a/application/Espo/Resources/metadata/entityDefs/Settings.json +++ b/application/Espo/Resources/metadata/entityDefs/Settings.json @@ -565,6 +565,10 @@ "type": "int", "min": 1 }, + "massEmailMaxPerBatchCount": { + "type": "int", + "min": 1 + }, "massEmailVerp": { "type": "bool", "tooltip": true diff --git a/install/core/afterInstall/records.php b/install/core/afterInstall/records.php index 3ccd8213c0..16659917dc 100644 --- a/install/core/afterInstall/records.php +++ b/install/core/afterInstall/records.php @@ -72,7 +72,7 @@ return [ 'name' => 'Send Mass Emails', 'job' => 'ProcessMassEmail', 'status' => 'Active', - 'scheduling' => '15 * * * *', + 'scheduling' => '10,30,50 * * * *', ], [ 'name' => 'Auth Token Control', @@ -93,4 +93,4 @@ return [ 'scheduling' => '*/5 * * * *', ], ], -]; \ No newline at end of file +];