Skip to content

Commit

Permalink
Merge pull request #18 from wolxXx/reset-notifier-and-run
Browse files Browse the repository at this point in the history
Refactor Notify to fix notifier scheduling logic
  • Loading branch information
wolxXx authored Oct 28, 2024
2 parents ae42501 + 3d8ca27 commit 0185c88
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Util/Cron/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ class Notify

public function __construct()
{
$now = \Carbon\Carbon::now();

if (true === \DoEveryApp\Util\Registry::getInstance()->isNotifierRunning()) {
return;
$now = \Carbon\Carbon::now();
$notifierLastRun = \DoEveryApp\Util\Registry::getInstance()->getNotifierLastRun();
$force = false;
$lastCron = \Carbon\Carbon::create($notifierLastRun);
$lastCron->addHours(23);
if ($lastCron->gt($now)) {
$force = true;
}

$notifierLastRun = \DoEveryApp\Util\Registry::getInstance()->getNotifierLastRun();
$diff = $now->diff($notifierLastRun, true, ['y', 'm', 'd', 'h']);
if ($diff->d > 0 || $diff->h > 6) {
return;
if (true === \DoEveryApp\Util\Registry::getInstance()->isNotifierRunning()) {
if(true !== $force) {
return;
}
}

\DoEveryApp\Util\Registry::getInstance()->setNotifierRunning(true);
Expand Down Expand Up @@ -99,8 +102,8 @@ public function notify(): void
$notification::getRepository()->create($notification);
}
\DoEveryApp\Util\Mailing\Notify::send($worker, $tasks);
}catch (\Throwable $exception) {
\DoEveryApp\Util\DependencyContainer::getInstance()->getLogger()->error('notification mail failed. '.$exception->getMessage().\PHP_EOL.\PHP_EOL.$exception->getTraceAsString());
} catch (\Throwable $exception) {
\DoEveryApp\Util\DependencyContainer::getInstance()->getLogger()->error('notification mail failed. ' . $exception->getMessage() . \PHP_EOL . \PHP_EOL . $exception->getTraceAsString());
}
}
\DoEveryApp\Util\DependencyContainer::getInstance()
Expand Down

0 comments on commit 0185c88

Please sign in to comment.