Skip to content

Commit

Permalink
+ support for params
Browse files Browse the repository at this point in the history
  • Loading branch information
dusterio committed Nov 5, 2019
1 parent 4333aaf commit 68d2d62
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ cron:
url: "/worker/schedule"
schedule: "0 * * * *"
- name: "do:something"
- name: "do:something --param=1 -v"
url: "/worker/schedule"
schedule: "*/5 * * * *"
```
Expand Down
33 changes: 32 additions & 1 deletion src/Controllers/WorkerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,45 @@ public function schedule(Container $laravel, Kernel $kernel, Schedule $schedule,
return $this->response($messages);
}

/**
* @param string $command
* @return array
*/
protected function parseCommand($command)
{
$elements = explode(' ', $command);
$name = $elements[0];
if (count($elements) == 1) return [$name, []];

array_shift($elements);
$arguments = [];

array_map(function($parameter) use (&$arguments) {
if (strstr($parameter, '=')) {
$parts = explode('=', $parameter);
$arguments[$parts[0]] = $parts[1];
return;
}

$arguments[$parameter] = true;
}, $elements);

return [
$name,
$arguments
];
}

/**
* @param Kernel $kernel
* @param $command
* @return Response
*/
protected function runSpecificCommand(Kernel $kernel, $command)
{
$exitCode = $kernel->call($command);
list ($name, $arguments) = $this->parseCommand($command);

$exitCode = $kernel->call($name, $arguments);

return $this->response($exitCode);
}
Expand Down

0 comments on commit 68d2d62

Please sign in to comment.