Skip to content

Commit 68d2d62

Browse files
committedNov 5, 2019
+ support for params
1 parent 4333aaf commit 68d2d62

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ cron:
6767
url: "/worker/schedule"
6868
schedule: "0 * * * *"
6969
70-
- name: "do:something"
70+
- name: "do:something --param=1 -v"
7171
url: "/worker/schedule"
7272
schedule: "*/5 * * * *"
7373
```

‎src/Controllers/WorkerController.php

+32-1
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,45 @@ public function schedule(Container $laravel, Kernel $kernel, Schedule $schedule,
6565
return $this->response($messages);
6666
}
6767

68+
/**
69+
* @param string $command
70+
* @return array
71+
*/
72+
protected function parseCommand($command)
73+
{
74+
$elements = explode(' ', $command);
75+
$name = $elements[0];
76+
if (count($elements) == 1) return [$name, []];
77+
78+
array_shift($elements);
79+
$arguments = [];
80+
81+
array_map(function($parameter) use (&$arguments) {
82+
if (strstr($parameter, '=')) {
83+
$parts = explode('=', $parameter);
84+
$arguments[$parts[0]] = $parts[1];
85+
return;
86+
}
87+
88+
$arguments[$parameter] = true;
89+
}, $elements);
90+
91+
return [
92+
$name,
93+
$arguments
94+
];
95+
}
96+
6897
/**
6998
* @param Kernel $kernel
7099
* @param $command
71100
* @return Response
72101
*/
73102
protected function runSpecificCommand(Kernel $kernel, $command)
74103
{
75-
$exitCode = $kernel->call($command);
104+
list ($name, $arguments) = $this->parseCommand($command);
105+
106+
$exitCode = $kernel->call($name, $arguments);
76107

77108
return $this->response($exitCode);
78109
}

0 commit comments

Comments
 (0)
Please sign in to comment.