- WIP on Middleware to allows only one launch from a task which could be called at least twice due to having multiple cron attached to
This commit is contained in:
parent
c309facbd3
commit
ea92e0de8d
@ -41,18 +41,27 @@ 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);
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user