Timeout server SMTP
Aggiunto timeout del server SMTP per gestire al meglio l'invio sequenziale delle email.
This commit is contained in:
parent
62ebdbb999
commit
d7fd612dc9
|
@ -88,14 +88,14 @@ function executeHook(hook, token) {
|
||||||
|
|
||||||
var timeout;
|
var timeout;
|
||||||
if (result.execute) {
|
if (result.execute) {
|
||||||
timeout = 1;
|
startHook(hook);
|
||||||
} else {
|
} else {
|
||||||
timeout = 30;
|
timeout = 30;
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
startHook(hook);
|
startHook(hook);
|
||||||
}, timeout * 1000);
|
}, timeout * 1000);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Modules\Emails;
|
namespace Modules\Emails;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Hooks\Manager;
|
use Hooks\Manager;
|
||||||
use Notifications\EmailNotification;
|
use Notifications\EmailNotification;
|
||||||
|
|
||||||
|
@ -29,20 +30,32 @@ class EmailHook extends Manager
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$accounts = Account::all();
|
|
||||||
$diff = date('Y-m-d', strtotime('-4 hours'));
|
$diff = date('Y-m-d', strtotime('-4 hours'));
|
||||||
|
$failed = function ($query) use ($diff) {
|
||||||
|
$query->whereDate('failed_at', '<', $diff)
|
||||||
|
->orWhereNull('failed_at');
|
||||||
|
};
|
||||||
|
|
||||||
|
$accounts = Account::all();
|
||||||
$list = [];
|
$list = [];
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$mail = Mail::whereNull('sent_at')
|
$last_mail = $account->emails()->whereNotNull('sent_at')->orderBy('sent_at')->first();
|
||||||
->where('id_account', $account->id)
|
|
||||||
->whereNull('failed_at')
|
|
||||||
->orWhereDate('failed_at', '<', $diff)
|
|
||||||
->orderBy('created_at')
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if (!empty($mail)) {
|
// Controllo sul timeout dell'account
|
||||||
$list[] = $mail;
|
$date = new Carbon($last_mail->sent_at);
|
||||||
|
$now = new Carbon();
|
||||||
|
$diff = $date->diffInMilliseconds($now);
|
||||||
|
|
||||||
|
if (empty($last_mail) || $diff > $account->timeout) {
|
||||||
|
$mail = Mail::whereNull('sent_at')
|
||||||
|
->where('id_account', $account->id)
|
||||||
|
->where($failed)
|
||||||
|
->orderBy('created_at')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!empty($mail)) {
|
||||||
|
$list[] = $mail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ switch (post('op')) {
|
||||||
'from_address' => post('from_address'),
|
'from_address' => post('from_address'),
|
||||||
'encryption' => post('encryption'),
|
'encryption' => post('encryption'),
|
||||||
'pec' => post('pec'),
|
'pec' => post('pec'),
|
||||||
|
'timeout' => post('timeout'),
|
||||||
'ssl_no_verify' => post('ssl_no_verify'),
|
'ssl_no_verify' => post('ssl_no_verify'),
|
||||||
'predefined' => $predefined,
|
'predefined' => $predefined,
|
||||||
], ['id' => $id_record]);
|
], ['id' => $id_record]);
|
||||||
|
|
|
@ -63,8 +63,12 @@ include_once __DIR__.'/../../core.php';
|
||||||
{[ "type": "text", "label": "<?php echo tr('Username SMTP'); ?>", "name": "username", "value": "$username$" ]}
|
{[ "type": "text", "label": "<?php echo tr('Username SMTP'); ?>", "name": "username", "value": "$username$" ]}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-3">
|
||||||
{[ "type": "password", "label": "<?php echo tr('Password SMTP'); ?>", "class": "", "name": "password", "value": "$password$" ]}
|
{[ "type": "password", "label": "<?php echo tr('Password SMTP'); ?>", "name": "password", "value": "$password$" ]}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3">
|
||||||
|
{[ "type": "number", "label": "<?php echo tr('Timeout coda di invio (millisecondi)'); ?>", "name": "timeout", "value": "$timeout$", "decimals": 0 ]}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -419,7 +419,7 @@ INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`,
|
||||||
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'Completato', 'IF(completed_at IS NULL, ''No'', ''Si'')', 4, 1, 0, 1, 1);
|
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'Completato', 'IF(completed_at IS NULL, ''No'', ''Si'')', 4, 1, 0, 1, 1);
|
||||||
|
|
||||||
-- Modulo Stato email
|
-- Modulo Stato email
|
||||||
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Stato email', 'Stato email', 'stato_email', 'SELECT |select| FROM `em_emails` WHERE 1=1 AND (`em_emails`.`created_at` BETWEEN ''|period_start|'' AND ''|period_end|'' OR `em_emails`.`sent_at` IS NULL) HAVING 2=2', '', 'fa fa-spinner ', '2.4.11', '2.4.11', '1', (SELECT `id` FROM `zz_modules` t WHERE t.`name` = 'Gestione email'), '1', '1');
|
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Stato email', 'Coda di invio', 'stato_email', 'SELECT |select| FROM `em_emails` WHERE 1=1 AND (`em_emails`.`created_at` BETWEEN ''|period_start|'' AND ''|period_end|'' OR `em_emails`.`sent_at` IS NULL) HAVING 2=2', '', 'fa fa-spinner ', '2.4.11', '2.4.11', '1', (SELECT `id` FROM `zz_modules` t WHERE t.`name` = 'Gestione email'), '1', '1');
|
||||||
|
|
||||||
INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `default`, `visible`, `format`) VALUES
|
INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `default`, `visible`, `format`) VALUES
|
||||||
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'id', 'id', 1, 0, 0, 1, 0, 0),
|
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'id', 'id', 1, 0, 0, 1, 0, 0),
|
||||||
|
@ -432,3 +432,4 @@ INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`,
|
||||||
|
|
||||||
ALTER TABLE `em_templates` CHANGE `id_smtp` `id_account` INT(11) NOT NULL;
|
ALTER TABLE `em_templates` CHANGE `id_smtp` `id_account` INT(11) NOT NULL;
|
||||||
ALTER TABLE `em_print_template` CHANGE `id_email` `id_template` INT(11) NOT NULL;
|
ALTER TABLE `em_print_template` CHANGE `id_email` `id_template` INT(11) NOT NULL;
|
||||||
|
ALTER TABLE `em_accounts` ADD `timeout` INT(11) NOT NULL DEFAULT 1000;
|
||||||
|
|
Loading…
Reference in New Issue