Improve select on tasks

This commit is contained in:
Anton Medvedev 2020-10-10 22:37:06 +02:00
parent e227623ba6
commit 83022a3927
4 changed files with 10 additions and 6 deletions

View File

@ -82,7 +82,8 @@ class Master
}
if ($task->isLocal()) {
$plannedHosts = [new Localhost('localhost')];
// Special name for local() tasks.
$plannedHosts = [new Localhost('local')];
}
if ($limit === 1 || count($plannedHosts) === 1) {
@ -106,10 +107,9 @@ class Master
}
} else {
foreach (array_chunk($hosts, $limit) as $chunk) {
$selector = $task->getSelector();
$selectedHosts = [];
foreach ($chunk as $currentHost) {
if ($selector === null || Selector::apply($selector, $currentHost)) {
if (Selector::apply($task->getSelector(), $currentHost)) {
$selectedHosts[] = $currentHost;
}
}

View File

@ -52,12 +52,12 @@ class Planner
*/
public function commit(array $hosts, Task $task)
{
if (count($hosts) === 1 && $hosts[0]->getAlias() === 'localhost') {
if (count($hosts) === 1 && $hosts[0]->getAlias() === 'local') {
$row = [];
foreach ($this->template as $alias) {
$row[] = "-";
}
$row[] = $task->getName() . " (local)";
$row[] = $task->getName();
$this->table->addRow($row);
return;
}

View File

@ -39,6 +39,10 @@ class Selector
public static function apply($conditions, Host $host)
{
if (empty($conditions)) {
return true;
}
$labels = $host->get('labels', []);
$labels['__host__'] = $host->getAlias();
$labels['__all__'] = 'yes';

View File

@ -83,7 +83,7 @@ class Task
{
$this->name = $name;
$this->callback = $callback;
$this->selector = Selector::parse('all');
$this->selector = null;
}
public function run(Context $context)