Homec4science

Discard futures after they resolve in phage

Authored by Mike Riley <mriley@uberatc.com> on Aug 9 2016, 20:35.

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

Committed
Mike Riley <mikeriley@yelirekim.com>Aug 9 2016, 20:35
Pushed
aubortMar 17 2017, 12:03
Parents
rPHU8b2800566ab9: Set "history.immutable" to "false" explicitly in .arcconfig in libphutil
Branches
Unknown
Tags
Unknown

Event Timeline

Mike Riley <mikeriley@yelirekim.com> committed rPHU73e2a1984abf: Discard futures after they resolve in phage (authored by Mike Riley <mriley@uberatc.com>).Aug 9 2016, 20:35