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 $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class));
|
||||
return $cronardMiddleware->fromAnnotations($c->get(TaskFetcher::class));
|
||||
},
|
||||
|
||||
TaskFetcher::class => function($c) {
|
||||
|
||||
@@ -32,7 +32,7 @@ class CronardMiddleware implements MiddlewareInterface
|
||||
{
|
||||
if ( $this->cronKey === ( $request->getQueryParams()['cronkey'] ?? false ) ) {
|
||||
$response = $this->response->call($this);
|
||||
|
||||
|
||||
$this->launch([
|
||||
$request,
|
||||
$response,
|
||||
|
||||
+19
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user