Discard futures after they resolve in phage
Summary: The list of futures that the PHP agent maintains is never emptied after futures resolve. On subsequent passes through the loop in execute, all past futures are executed repeatedly.
Test Plan:
This didn't work previously.
<?php final class CIAWSDrydockHostCommandWorkflow extends CIAWSManagementWorkflow { protected function didConstruct() { $this ->setName('drydock-command') ->setSynopsis(pht('Interact with a drydock host.')) ->setArguments([ [ 'name' => 'lease', 'param' => 'id', 'help' => pht('ID of drydock lease to command.'), ], ]); } public function execute(PhutilArgumentParser $args) { $resource_id = $this->requireArgument($args, 'lease'); $viewer = PhabricatorUser::getOmnipotentUser(); $lease = (new DrydockLeaseQuery()) ->setViewer($viewer) ->withIDs([$resource_id]) ->executeOne(); $boot = new PhagePHPAgentBootloader(); $ssh = $lease->getInterface(DrydockCommandInterface::INTERFACE_TYPE); $exec = $ssh->getExecFuture('%C', $boot->getBootCommand()); $exec->write($boot->getBootSequence(), $keep_open = true); $exec_channel = new PhutilExecChannel($exec); $agent = new PhutilJSONProtocolChannel($exec_channel); $console = PhutilConsole::getConsole(); $cmd = null; $key = 1; while ($cmd !== 'exit') { $console->writeOut('**>** '); $cmd = fgets(STDIN); $cmd = rtrim($cmd, "\r\n"); $agent->write([ 'type' => 'EXEC', 'key' => $key++, 'command' => $cmd, ]); $message = $agent->waitForMessage(); $console->writeOut('%s', $message['stdout']); $console->writeErr('%s', $message['stderr']); } $agent->write(['type' => 'EXIT']); return 0; } }
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: epriestley
Differential Revision: https://secure.phabricator.com/D16177