From 756dbb4641d98f3a22df7ea6957f47ab8ff8e667 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 2 May 2016 10:32:34 -0400 Subject: [PATCH] - Updates daemon status to CONSTs - Uncomments temporary commented out code - Removes unnecessary exception handles in Public API --- lib/Config/PublicAPI.php | 24 +++++++++--------------- lib/Cron/CronHelper.php | 6 +++++- lib/Cron/Daemon.php | 19 ++++++++++--------- lib/Cron/Supervisor.php | 6 +++--- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/lib/Config/PublicAPI.php b/lib/Config/PublicAPI.php index da29c72108..d75c6d52d9 100644 --- a/lib/Config/PublicAPI.php +++ b/lib/Config/PublicAPI.php @@ -52,25 +52,19 @@ class PublicAPI { } function track() { - try { - if($this->action === 'click') { - $track_class = new Clicks($this->data); - } - if($this->action === 'open') { - $track_class = new Opens($this->data); - } - if(!isset($track_class)) return; - $track_class->track(); - } catch(\Exception $e) { + if($this->action === 'click') { + $track_class = new Clicks($this->data); } + if($this->action === 'open') { + $track_class = new Opens($this->data); + } + if(!isset($track_class)) return; + $track_class->track(); } function viewInBrowser() { - try { - $viewer = new ViewInBrowser($this->_decodeData()); - $viewer->view(); - } catch(\Exception $e) { - } + $viewer = new ViewInBrowser($this->_decodeData()); + $viewer->view(); } private function _checkAndCallMethod($class, $method, $terminate_request = false) { diff --git a/lib/Cron/CronHelper.php b/lib/Cron/CronHelper.php index 670e9842d0..ace9952765 100644 --- a/lib/Cron/CronHelper.php +++ b/lib/Cron/CronHelper.php @@ -10,10 +10,14 @@ class CronHelper { const DAEMON_EXECUTION_LIMIT = 20; const DAEMON_EXECUTION_TIMEOUT = 35; const DAEMON_REQUEST_TIMEOUT = 2; + const DAEMON_STATUS_STOPPED = 'stopped'; + const DAEMON_STATUS_STOPPING = 'stopping'; + const DAEMON_STATUS_STARTED = 'started'; + const DAEMON_STATUS_STARTING = 'starting'; static function createDaemon($token) { $daemon = array( - 'status' => 'starting', + 'status' => self::DAEMON_STATUS_STARTING, 'counter' => 0, 'token' => $token ); diff --git a/lib/Cron/Daemon.php b/lib/Cron/Daemon.php index 6037c853b0..4724f21832 100644 --- a/lib/Cron/Daemon.php +++ b/lib/Cron/Daemon.php @@ -12,7 +12,7 @@ class Daemon { public $daemon; public $data; public $refreshed_token; - const daemon_request_timeout = 5; + const DAEMON_REQUEST_TIMEOUT = 5; private $timer; function __construct($data) { @@ -37,11 +37,12 @@ class Daemon { } $this->abortIfStopped($daemon); try { -/* $scheduler = new Scheduler(); + $scheduler = new Scheduler(); $scheduler->process($this->timer); $queue = new SendingQueue(); - $queue->process($this->timer);*/ + $queue->process($this->timer); } catch(\Exception $e) { + // continue processing, no need to catch errors } $elapsed_time = microtime(true) - $this->timer; if($elapsed_time < CronHelper::DAEMON_EXECUTION_LIMIT) { @@ -55,8 +56,8 @@ class Daemon { } $daemon['counter']++; $this->abortIfStopped($daemon); - if($daemon['status'] === 'starting') { - $daemon['status'] = 'started'; + if($daemon['status'] === CronHelper::DAEMON_STATUS_STARTING) { + $daemon['status'] = CronHelper::DAEMON_STATUS_STARTED; } $daemon['token'] = $this->token; CronHelper::saveDaemon($daemon); @@ -64,9 +65,9 @@ class Daemon { } function abortIfStopped($daemon) { - if($daemon['status'] === 'stopped') exit; - if($daemon['status'] === 'stopping') { - $daemon['status'] = 'stopped'; + if($daemon['status'] === CronHelper::DAEMON_STATUS_STOPPED) exit; + if($daemon['status'] === CronHelper::DAEMON_STATUS_STOPPING) { + $daemon['status'] = CronHelper::DAEMON_STATUS_STOPPING; CronHelper::saveDaemon($daemon); exit; } @@ -77,7 +78,7 @@ class Daemon { } function callSelf() { - CronHelper::accessDaemon($this->token, self::daemon_request_timeout); + CronHelper::accessDaemon($this->token, self::DAEMON_REQUEST_TIMEOUT); exit; } } \ No newline at end of file diff --git a/lib/Cron/Supervisor.php b/lib/Cron/Supervisor.php index 5c5883865f..e316498b9b 100644 --- a/lib/Cron/Supervisor.php +++ b/lib/Cron/Supervisor.php @@ -23,7 +23,7 @@ class Supervisor { // if the daemon is stopped, return its status and do nothing if(!$this->force_run && isset($daemon['status']) && - $daemon['status'] === 'stopped' + $daemon['status'] === CronHelper::DAEMON_STATUS_STOPPED ) { return $this->formatDaemonStatusMessage($daemon['status']); @@ -40,8 +40,8 @@ class Supervisor { elseif($elapsed_time < CronHelper::DAEMON_EXECUTION_TIMEOUT && $this->force_run && in_array($daemon['status'], array( - 'stopping', - 'starting' + CronHelper::DAEMON_STATUS_STOPPING, + CronHelper::DAEMON_STATUS_STARTING )) ) { return $this->formatDaemonStatusMessage($daemon['status']);