Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78daf88d67 | ||
|
|
2f78a1b97d | ||
|
|
ea92e0de8d | ||
|
|
c309facbd3 |
No files matched your search
+1
-1
@@ -17,7 +17,7 @@ return [
|
|||||||
return new HtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
|
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) {
|
TaskFetcher::class => function($c) {
|
||||||
|
|||||||
+19
-5
@@ -18,8 +18,13 @@ trait CronardTrait {
|
|||||||
$cronard = new Cronard();
|
$cronard = new Cronard();
|
||||||
|
|
||||||
foreach($this->crontabs as $tab) {
|
foreach($this->crontabs as $tab) {
|
||||||
$cronard->setTab(stripslashes($tab['cron']));
|
try {
|
||||||
$cronard->run(array_merge($this->variables, $variables), $tab['callback']);
|
$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
|
public function fromAnnotations(TaskFetcher $fetcher) : self
|
||||||
{
|
{
|
||||||
$tasks = [];
|
$launched = [];
|
||||||
|
|
||||||
foreach($fetcher->compile() as $task) {
|
foreach($fetcher->compile() as $task) {
|
||||||
$this->crontabs[] = [
|
$this->crontabs[] = [
|
||||||
'cron' => $task['annotation']->cron,
|
'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 ) {
|
if ( $task['annotation']->method ?? false ) {
|
||||||
$request = $request->withMethod($task['annotation']->method);
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user