- Updates daemon status to CONSTs
- Uncomments temporary commented out code - Removes unnecessary exception handles in Public API
This commit is contained in:
@ -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) {
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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']);
|
||||
|
Reference in New Issue
Block a user