- Updates daemon status to CONSTs

- Uncomments temporary commented out code
- Removes unnecessary exception handles in Public API
This commit is contained in:
Vlad
2016-05-02 10:32:34 -04:00
parent b38742ddc0
commit 756dbb4641
4 changed files with 27 additions and 28 deletions

View File

@ -52,25 +52,19 @@ class PublicAPI {
} }
function track() { function track() {
try { if($this->action === 'click') {
if($this->action === 'click') { $track_class = new Clicks($this->data);
$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 === 'open') {
$track_class = new Opens($this->data);
}
if(!isset($track_class)) return;
$track_class->track();
} }
function viewInBrowser() { function viewInBrowser() {
try { $viewer = new ViewInBrowser($this->_decodeData());
$viewer = new ViewInBrowser($this->_decodeData()); $viewer->view();
$viewer->view();
} catch(\Exception $e) {
}
} }
private function _checkAndCallMethod($class, $method, $terminate_request = false) { private function _checkAndCallMethod($class, $method, $terminate_request = false) {

View File

@ -10,10 +10,14 @@ class CronHelper {
const DAEMON_EXECUTION_LIMIT = 20; const DAEMON_EXECUTION_LIMIT = 20;
const DAEMON_EXECUTION_TIMEOUT = 35; const DAEMON_EXECUTION_TIMEOUT = 35;
const DAEMON_REQUEST_TIMEOUT = 2; 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) { static function createDaemon($token) {
$daemon = array( $daemon = array(
'status' => 'starting', 'status' => self::DAEMON_STATUS_STARTING,
'counter' => 0, 'counter' => 0,
'token' => $token 'token' => $token
); );

View File

@ -12,7 +12,7 @@ class Daemon {
public $daemon; public $daemon;
public $data; public $data;
public $refreshed_token; public $refreshed_token;
const daemon_request_timeout = 5; const DAEMON_REQUEST_TIMEOUT = 5;
private $timer; private $timer;
function __construct($data) { function __construct($data) {
@ -37,11 +37,12 @@ class Daemon {
} }
$this->abortIfStopped($daemon); $this->abortIfStopped($daemon);
try { try {
/* $scheduler = new Scheduler(); $scheduler = new Scheduler();
$scheduler->process($this->timer); $scheduler->process($this->timer);
$queue = new SendingQueue(); $queue = new SendingQueue();
$queue->process($this->timer);*/ $queue->process($this->timer);
} catch(\Exception $e) { } catch(\Exception $e) {
// continue processing, no need to catch errors
} }
$elapsed_time = microtime(true) - $this->timer; $elapsed_time = microtime(true) - $this->timer;
if($elapsed_time < CronHelper::DAEMON_EXECUTION_LIMIT) { if($elapsed_time < CronHelper::DAEMON_EXECUTION_LIMIT) {
@ -55,8 +56,8 @@ class Daemon {
} }
$daemon['counter']++; $daemon['counter']++;
$this->abortIfStopped($daemon); $this->abortIfStopped($daemon);
if($daemon['status'] === 'starting') { if($daemon['status'] === CronHelper::DAEMON_STATUS_STARTING) {
$daemon['status'] = 'started'; $daemon['status'] = CronHelper::DAEMON_STATUS_STARTED;
} }
$daemon['token'] = $this->token; $daemon['token'] = $this->token;
CronHelper::saveDaemon($daemon); CronHelper::saveDaemon($daemon);
@ -64,9 +65,9 @@ class Daemon {
} }
function abortIfStopped($daemon) { function abortIfStopped($daemon) {
if($daemon['status'] === 'stopped') exit; if($daemon['status'] === CronHelper::DAEMON_STATUS_STOPPED) exit;
if($daemon['status'] === 'stopping') { if($daemon['status'] === CronHelper::DAEMON_STATUS_STOPPING) {
$daemon['status'] = 'stopped'; $daemon['status'] = CronHelper::DAEMON_STATUS_STOPPING;
CronHelper::saveDaemon($daemon); CronHelper::saveDaemon($daemon);
exit; exit;
} }
@ -77,7 +78,7 @@ class Daemon {
} }
function callSelf() { function callSelf() {
CronHelper::accessDaemon($this->token, self::daemon_request_timeout); CronHelper::accessDaemon($this->token, self::DAEMON_REQUEST_TIMEOUT);
exit; exit;
} }
} }

View File

@ -23,7 +23,7 @@ class Supervisor {
// if the daemon is stopped, return its status and do nothing // if the daemon is stopped, return its status and do nothing
if(!$this->force_run && if(!$this->force_run &&
isset($daemon['status']) && isset($daemon['status']) &&
$daemon['status'] === 'stopped' $daemon['status'] === CronHelper::DAEMON_STATUS_STOPPED
) { ) {
return $this->formatDaemonStatusMessage($daemon['status']); return $this->formatDaemonStatusMessage($daemon['status']);
@ -40,8 +40,8 @@ class Supervisor {
elseif($elapsed_time < CronHelper::DAEMON_EXECUTION_TIMEOUT && elseif($elapsed_time < CronHelper::DAEMON_EXECUTION_TIMEOUT &&
$this->force_run && $this->force_run &&
in_array($daemon['status'], array( in_array($daemon['status'], array(
'stopping', CronHelper::DAEMON_STATUS_STOPPING,
'starting' CronHelper::DAEMON_STATUS_STARTING
)) ))
) { ) {
return $this->formatDaemonStatusMessage($daemon['status']); return $this->formatDaemonStatusMessage($daemon['status']);