Skip to content
Snippets Groups Projects
Unverified Commit 65bf234c authored by Christoph Wurst's avatar Christoph Wurst
Browse files

In cron always sync mailboxes before sync'ing their messages

parent 2c76e989
No related branches found
No related tags found
No related merge requests found
......@@ -25,8 +25,8 @@ declare(strict_types=1);
namespace OCA\Mail\BackgroundJob;
use Exception;
use OCA\Mail\Exception\IncompleteSyncException;
use OCA\Mail\IMAP\MailboxSync;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\Sync\ImapToDbSynchronizer;
use OCP\AppFramework\Db\DoesNotExistException;
......@@ -34,20 +34,28 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\TimedJob;
use OCP\ILogger;
use Throwable;
class SyncJob extends TimedJob {
/** @var AccountService */
private $accountService;
/** @var ImapToDbSynchronizer */
private $syncService;
/** @var MailboxSync */
private $mailboxSync;
/** @var ILogger */
private $logger;
/** @var IJobList */
private $jobList;
public function __construct(ITimeFactory $time,
AccountService $accountService,
MailboxSync $mailboxSync,
ImapToDbSynchronizer $syncService,
ILogger $logger,
IJobList $jobList) {
......@@ -55,6 +63,7 @@ class SyncJob extends TimedJob {
$this->accountService = $accountService;
$this->syncService = $syncService;
$this->mailboxSync = $mailboxSync;
$this->logger = $logger;
$this->setInterval(3600);
......@@ -73,13 +82,16 @@ class SyncJob extends TimedJob {
}
try {
$this->mailboxSync->sync($account, true);
$this->syncService->syncAccount($account);
} catch (IncompleteSyncException $e) {
$this->logger->logException($e, [
'level' => ILogger::WARN,
]);
} catch (Exception $e) {
$this->logger->logException($e);
} catch (Throwable $e) {
$this->logger->logException($e, [
'message' => 'Cron mail sync failed: ' . $e->getMessage(),
]);
}
}
}
......@@ -151,7 +151,7 @@ class ImapToDbSynchronizer {
// Just rethrow, don't wrap into another exception
throw $e;
} catch (Throwable $e) {
throw new ServiceException('Sync failed: ' . $e->getMessage(), 0, $e);
throw new ServiceException('Sync failed for ' . $account->getId() . ':' . $mailbox->getName() . ': ' . $e->getMessage(), 0, $e);
} finally {
if ($criteria & Horde_Imap_Client::SYNC_VANISHEDUIDS) {
$this->mailboxMapper->unlockFromVanishedSync($mailbox);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment