HomePhabricator

Discard futures after they resolve in phage

Description

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

Details

Provenance
yelirekimAuthored on Aug 9 2016, 6:35 PM
yelirekimPushed on Aug 9 2016, 6:35 PM
Reviewer
Blessed Reviewers
Differential Revision
D16177: Discard futures after they resolve in phage
Parents
rPHU8b2800566ab9: Set "history.immutable" to "false" explicitly in .arcconfig in libphutil
Branches
Unknown
Tags
Unknown
Build Status
Buildable 13276
Build 17019: Run Core Tests