Created
November 16, 2021 07:19
-
-
Save dusta/9578ca16c6da65e6ba7001f44b55fa26 to your computer and use it in GitHub Desktop.
Example Dframe/Cron lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Dframe\Router\Response; | |
set_time_limit(0); | |
ini_set('max_execution_time', 0); | |
date_default_timezone_set('Europe/Warsaw'); | |
require_once dirname(__DIR__) . '/../../../vendor/autoload.php'; | |
require_once dirname(__DIR__) . '/../../../web/config.php'; | |
/** | |
* An anonymous Cron class that calls itself | |
*/ | |
return (new class () extends \Dframe\Cron\Task | |
{ | |
/** | |
* Init function | |
* | |
* @return array | |
*/ | |
public function init() | |
{ | |
$cron = $this->inLock('mail', [$this->loadModel('Mail/Mail', 'Mail'), 'sendMails'], []); | |
if ($cron['return'] == true) { | |
$mail = $cron['response']; | |
return Response::renderJSON(['code' => 200, 'message' => 'Cron Complete', 'data' => ['mail' => ['data' => $mail['response']]]]); | |
} | |
return Response::renderJSON(['code' => 403, 'message' => 'Cron in Lock'])->status(403); | |
} | |
} | |
)->init()->display(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment