Skip to content

Commit 57fd75e

Browse files
committed
Feature: on failure tasks.
1 parent 16e9ebb commit 57fd75e

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

recipe/common.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,18 @@
520520
}
521521
});
522522

523+
523524
/**
524525
* Success message
525526
*/
526527
task('success', function () {
527528
Deployer::setDefault('terminate_message', '<info>Successfully deployed!</info>');
528529
})->once()->setPrivate();
530+
531+
532+
/**
533+
* Deploy failure
534+
*/
535+
task('deploy:failed', function () {
536+
})->setPrivate();
537+
onFailure('deploy', 'deploy:failed');

src/Console/TaskCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ protected function execute(Input $input, Output $output)
7979
$executor->run($tasks, $servers, $environments, $input, $output);
8080
} catch (\Exception $exception) {
8181
\Deployer\logger($exception->getMessage(), Logger::ERROR);
82+
83+
// Check if we have tasks to execute on failure.
84+
if ($this->deployer['onFailure']->has($this->getName())) {
85+
$taskName = $this->deployer['onFailure']->get($this->getName());
86+
$tasks = $this->deployer->getScriptManager()->getTasks($taskName, $stage);
87+
$executor->run($tasks, $servers, $environments, $input, $output);
88+
}
89+
8290
throw $exception;
8391
}
8492

src/Deployer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public function __construct(Application $console, Console\Input\InputInterface $
8888
$this['stageStrategy'] = function ($c) {
8989
return new StageStrategy($c['servers'], $c['environments'], $c['config']['default_stage']);
9090
};
91+
$this['onFailure'] = function () {
92+
return new Collection();
93+
};
9194

9295
/******************************
9396
* Logger *

src/functions.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ function after($it, $that)
193193
$afterTask->addAfter($that);
194194
}
195195

196+
/**
197+
* Setup which task run on failure of first.
198+
*
199+
* @param string $it
200+
* @param string $that
201+
*/
202+
function onFailure($it, $that)
203+
{
204+
$deployer = Deployer::get();
205+
$deployer['onFailure']->set($it, $that);
206+
}
207+
196208
/**
197209
* Add users arguments.
198210
*

0 commit comments

Comments
 (0)