4 Commits
2 changed files with 20 additions and 6 deletions

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ return [
return new HtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
}, []);
return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class));
return $cronardMiddleware->fromAnnotations($c->get(TaskFetcher::class));
},
TaskFetcher::class => function($c) {
+19 -5
View File
@@ -18,8 +18,13 @@ trait CronardTrait {
$cronard = new Cronard();
foreach($this->crontabs as $tab) {
$cronard->setTab(stripslashes($tab['cron']));
$cronard->run(array_merge($this->variables, $variables), $tab['callback']);
try {
$cronard->setTab(stripslashes($tab['cron']));
$cronard->run(array_merge($this->variables, $variables), $tab['callback']);
}
catch(\Throwable $ex) {
error_log($ex->getMessage());
}
}
}
@@ -41,17 +46,26 @@ trait CronardTrait {
public function fromAnnotations(TaskFetcher $fetcher) : self
{
$tasks = [];
$launched = [];
foreach($fetcher->compile() as $task) {
$this->crontabs[] = [
'cron' => $task['annotation']->cron,
'callback' => function(ServerRequestInterface $request, ResponseInterface $response, ContainerInterface $container) use ($task) {
'callback' => function(ServerRequestInterface $request, ResponseInterface $response, ContainerInterface $container) use ($task, & $launched) {
if ( $task['annotation']->method ?? false ) {
$request = $request->withMethod($task['annotation']->method);
}
return $container->make($task['class'])->{$task['method']}($request->withAttribute('lean.cronard', $task['annotation']), []);
$uid = sprintf("%s::%s", $task['class'], $task['method']);
if ( empty($launched[$uid]) ) {
$launched[$uid] = true;
return $container->make($task['class'])->{$task['method']}($request->withAttribute('lean.cronard', $task['annotation']), []);
}
else {
return null;
}
}
];
}