- Fixes API endpoint naming convention
- Generates/saves cron daemon token as soon as its executed
This commit is contained in:
@ -34,13 +34,14 @@ class API {
|
|||||||
$this->terminateRequest(self::API_RESPONSE_CODE_ERROR, __('Invalid API endpoint.'));
|
$this->terminateRequest(self::API_RESPONSE_CODE_ERROR, __('Invalid API endpoint.'));
|
||||||
}
|
}
|
||||||
$this->callEndpoint(
|
$this->callEndpoint(
|
||||||
self::ENDPOINT_NAMESPACE . $this->endpoint,
|
$this->endpoint,
|
||||||
$this->action,
|
$this->action,
|
||||||
$this->data
|
$this->data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function callEndpoint($endpoint, $action, $data) {
|
function callEndpoint($endpoint, $action, $data) {
|
||||||
|
$endpoint = self::ENDPOINT_NAMESPACE . ucfirst($endpoint);
|
||||||
if(!method_exists($endpoint, $action)) {
|
if(!method_exists($endpoint, $action)) {
|
||||||
$this->terminateRequest(self::API_RESPONSE_CODE_ERROR, __('Invalid API action.'));
|
$this->terminateRequest(self::API_RESPONSE_CODE_ERROR, __('Invalid API action.'));
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ class Daemon {
|
|||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
$daemon = $this->daemon;
|
$daemon = $this->daemon;
|
||||||
set_time_limit(0);
|
|
||||||
if(!$daemon) {
|
if(!$daemon) {
|
||||||
$this->abortWithError(__('Daemon does not exist.'));
|
$this->abortWithError(__('Daemon does not exist.'));
|
||||||
}
|
}
|
||||||
@ -39,6 +38,8 @@ class Daemon {
|
|||||||
) {
|
) {
|
||||||
$this->abortWithError(__('Invalid or missing token.'));
|
$this->abortWithError(__('Invalid or missing token.'));
|
||||||
}
|
}
|
||||||
|
$daemon['token'] = $this->token;
|
||||||
|
CronHelper::saveDaemon($daemon);
|
||||||
$this->abortIfStopped($daemon);
|
$this->abortIfStopped($daemon);
|
||||||
try {
|
try {
|
||||||
$scheduler = new SchedulerWorker($this->timer);
|
$scheduler = new SchedulerWorker($this->timer);
|
||||||
@ -55,14 +56,13 @@ class Daemon {
|
|||||||
// after each execution, re-read daemon data in case its status was changed
|
// after each execution, re-read daemon data in case its status was changed
|
||||||
// its status has changed
|
// its status has changed
|
||||||
$daemon = CronHelper::getDaemon();
|
$daemon = CronHelper::getDaemon();
|
||||||
if(!$daemon || $daemon['token'] !== $this->data['token']) {
|
if(!$daemon || $daemon['token'] !== $this->token) {
|
||||||
$this->terminateRequest();
|
$this->terminateRequest();
|
||||||
}
|
}
|
||||||
$this->abortIfStopped($daemon);
|
$this->abortIfStopped($daemon);
|
||||||
if($daemon['status'] === self::STATUS_STARTING) {
|
if($daemon['status'] === self::STATUS_STARTING) {
|
||||||
$daemon['status'] = self::STATUS_STARTED;
|
$daemon['status'] = self::STATUS_STARTED;
|
||||||
}
|
}
|
||||||
$daemon['token'] = $this->token;
|
|
||||||
CronHelper::saveDaemon($daemon);
|
CronHelper::saveDaemon($daemon);
|
||||||
$this->callSelf();
|
$this->callSelf();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user