Skip to content

Instantly share code, notes, and snippets.

@dusta
Created November 16, 2021 07:19
Show Gist options
  • Save dusta/9578ca16c6da65e6ba7001f44b55fa26 to your computer and use it in GitHub Desktop.
Save dusta/9578ca16c6da65e6ba7001f44b55fa26 to your computer and use it in GitHub Desktop.
Example Dframe/Cron lock
<?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