Browse Source

changes @ deploy command. added rollback exception functionality.

1.0
Alex V Kotelnikov 10 years ago
parent
commit
438a81542e
  1. 28
      Mage/Command/BuiltIn/DeployCommand.php
  2. 23
      Mage/Task/RollbackException.php

28
Mage/Command/BuiltIn/DeployCommand.php

@ -3,6 +3,7 @@
* This file is part of the Magallanes package. * This file is part of the Magallanes package.
* *
* (c) Andrés Montañez <andres@andresmontanez.com> * (c) Andrés Montañez <andres@andresmontanez.com>
* (c) Alex V Kotelnikov <gudron@gudron.me>
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
@ -16,6 +17,7 @@ use Mage\Task\Factory;
use Mage\Task\AbstractTask; use Mage\Task\AbstractTask;
use Mage\Task\Releases\SkipOnOverride; use Mage\Task\Releases\SkipOnOverride;
use Mage\Task\ErrorWithMessageException; use Mage\Task\ErrorWithMessageException;
use Mage\Task\RollbackException;
use Mage\Task\SkipException; use Mage\Task\SkipException;
use Mage\Console; use Mage\Console;
use Mage\Config; use Mage\Config;
@ -428,6 +430,27 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
} }
} }
protected function runRollbackTask(){
$hosts = $this->getConfig()->getHosts();
if (count($hosts) == 0) {
Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, unable to get releases.</dark_gray>', 1, 3);
} else {
$result = true;
foreach ($hosts as $host) {
$this->getConfig()->setHost($host);
$this->getConfig()->setReleaseId(-1);
$task = Factory::get('releases/rollback', $this->getConfig());
$task->init();
$result = $task->run() && $result;
}
return $result;
}
return false;
}
/** /**
* Runs a Task * Runs a Task
* *
@ -461,6 +484,11 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
Console::output('<red>FAIL</red>', 0); Console::output('<red>FAIL</red>', 0);
$result = false; $result = false;
} }
} catch (RollbackException $e) {
Console::output('<red>FAIL, Rollback started</red> [Message: ' . $e->getMessage() . ']', 0);
$this->runRollbackTask();
$result = false;
} catch (ErrorWithMessageException $e) { } catch (ErrorWithMessageException $e) {
Console::output('<red>FAIL</red> [Message: ' . $e->getMessage() . ']', 0); Console::output('<red>FAIL</red> [Message: ' . $e->getMessage() . ']', 0);
$result = false; $result = false;

23
Mage/Task/RollbackException.php

@ -0,0 +1,23 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Alex V Kotelnikov <gudron@gudron.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task;
use Exception;
/**
* Exception that indicates that the Task was Failed and rollback needed
*
* @author Alex V Kotelnikov <gudron@gudron.me>
*/
class RollbackException extends Exception
{
}
Loading…
Cancel
Save