Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Option to control task execution per node #309

Open
chrosey opened this issue Oct 11, 2019 · 12 comments
Open

[Feature] Option to control task execution per node #309

chrosey opened this issue Oct 11, 2019 · 12 comments
Labels

Comments

@chrosey
Copy link

chrosey commented Oct 11, 2019

Expected Behavior

Add an option to control whether a task is executed on a node.

Actual Behavior

Unless defined, every Task is run on every node the Application ist hosted on. This is not necessary for Tasks that need to run once only.

@simonschaufi
Copy link
Collaborator

@chrosey Can you give me a usecase for this?

@t3easy
Copy link
Collaborator

t3easy commented Feb 16, 2020

Database migration, upgrade wizards,...

@chrosey
Copy link
Author

chrosey commented Apr 21, 2020

I may have an addition:
Can I adjust task options per node? (Example: Customizing the host header for the WebOpCache ResetExecutionTask)

@simonschaufi
Copy link
Collaborator

@chrosey currently this is not possible. Everything is bound to an Application but you can of course write you own Tasks and since you get the node as parameter, you can do everything you want.

@t3easy
Copy link
Collaborator

t3easy commented Apr 21, 2020

@simonschaufi Sorry, but this is not true.

@chrosey You can add options to a node which are merged with other options:

$node->getOptions(),

Then you must not configure the same option at the deployment, globalTaskOptions ($application->setOption('TYPO3\\Surf\\Task\\Package\\GitTask[hardClean]', true);), or at the task itselve.

Maybe we should write the order with examples to the documentation.

@simonschaufi
Copy link
Collaborator

simonschaufi commented Apr 21, 2020

Ok. I was really not aware of this. But is it true that you cannot bind a task only to a defined Node meaning all tasks will run on all nodes.

@chrosey
Copy link
Author

chrosey commented Apr 21, 2020

@t3easy I tried that with opcache-reset.

foreach ($targets1 as $t) {
    $node = new Node($t);
    $node->setHostname($t);
    $node->setOption('username', $deploymentUser);
    $node->setOption(
        \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask::class,
        [
            'scriptIdentifier' => 'erase-all-humans',
            'baseUrl' => 'https://'.$node->getHostname(),
            'stream_context' => [
                'http' => [
                    'header' => 'Host: example.com',
                ],
                'ssl' => [
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                ],
            ],
        ]
    );
    $application->addNode($node);
}

but there is an Error while deploying.

Node1 (CraftCMS) TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask
 Got exception "The required option "scriptIdentifier" is missing." rolling back.
 Rolling back TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask
 In Task.php line 79:
                                                         
   [TYPO3\Surf\Exception\InvalidConfigurationException]  
   The required option "scriptIdentifier" is missing.    
                                                         
 Exception trace:
   at /tmp/vendor/typo3/surf/src/Domain/Model/Task.php:79
  TYPO3\Surf\Domain\Model\Task->configureOptions() at /tmp/vendor/typo3/surf/src/Domain/Model/Task.php:48
  TYPO3\Surf\Domain\Model\Task->rollback() at /tmp/vendor/typo3/surf/src/Domain/Service/TaskManager.php:72
  TYPO3\Surf\Domain\Service\TaskManager->rollback() at /tmp/vendor/typo3/surf/src/Domain/Model/SimpleWorkflow.php:107
  TYPO3\Surf\Domain\Model\SimpleWorkflow->run() at /tmp/vendor/typo3/surf/src/Domain/Model/Deployment.php:184
  TYPO3\Surf\Domain\Model\Deployment->deploy() at /tmp/vendor/typo3/surf/src/Command/DeployCommand.php:66
  TYPO3\Surf\Command\DeployCommand->execute() at /tmp/vendor/symfony/console/Command/Command.php:255
  Symfony\Component\Console\Command\Command->run() at /tmp/vendor/symfony/console/Application.php:1012
  Symfony\Component\Console\Application->doRunCommand() at /tmp/vendor/typo3/surf/src/Cli/Symfony/ConsoleApplication.php:64
  TYPO3\Surf\Cli\Symfony\ConsoleApplication->doRunCommand() at /tmp/vendor/symfony/console/Application.php:272
  Symfony\Component\Console\Application->doRun() at /tmp/vendor/symfony/console/Application.php:148
  Symfony\Component\Console\Application->run() at /tmp/vendor/typo3/surf/src/Cli/Symfony/ConsoleApplication.php:49
  TYPO3\Surf\Cli\Symfony\ConsoleApplication->run() at /tmp/vendor/typo3/surf/surf:14

How should the Syntax to set these options be to let it work?

@chrosey
Copy link
Author

chrosey commented Apr 21, 2020

@simonschaufi thats why I would suggest maybe an boolean meta-option for abstract class Task which can be set like any other options to disable or enable Tasks for some Nodes.

@t3easy
Copy link
Collaborator

t3easy commented Apr 21, 2020

@chrosey You set the option wrong.
setOption only accepts one option with one value.
So it would be:

$node->setOption(
    \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask::class . '[scriptIdentifier]',
    'erase-all-humans'
);

@t3easy
Copy link
Collaborator

t3easy commented Apr 21, 2020

The option key for a global task option is always fullQualifiedClassName[optionName]

@chrosey
Copy link
Author

chrosey commented Apr 22, 2020

@t3easy: worked like a charm.

Did I miss this in the documentation?

@t3easy
Copy link
Collaborator

t3easy commented Apr 22, 2020

No, I guess there is no dokumentation how options can be set and how they are merged/overridden to the final result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants