{"_id":"573ed4bea233380e005db15b","user":"56b86c990094520d006b3c33","parentDoc":null,"project":"56b86cc286d2b0190070bcda","__v":0,"githubsync":"","version":{"_id":"573ed4bea233380e005db14d","__v":2,"project":"56b86cc286d2b0190070bcda","createdAt":"2016-05-20T09:11:26.847Z","releaseDate":"2016-05-20T09:11:26.847Z","categories":["573ed4bea233380e005db14e","573ed4bea233380e005db14f","573ed4bea233380e005db150","578bcf36bb7d810e00e01c05"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"master","version_clean":"0.3.0-0.4","version":"0.3-0.4"},"category":{"_id":"573ed4bea233380e005db14e","__v":0,"version":"573ed4bea233380e005db14d","project":"56b86cc286d2b0190070bcda","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-08T10:24:03.768Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-08T11:18:43.667Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"A task consists of one or more installation and/or deployment actions. They execute the actions by listening to events dispatched by the [Symfony Event Dispatcher][link-symfony-event-dispatcher] service.\n\n## Available tasks\n\nThe following tasks are included in Accompli:\n\n### Tasks for installing a release\n\n* [ComposerInstallTask](doc:composerinstalltask)\n* [CreateWorkspaceTask](doc:createworkspacetask)\n* [ExecuteCommandTask](doc:executecommandtask)\n* [FilePermissionTask](doc:filepermissiontask) \n* [RepositoryCheckoutTask](doc:repositorycheckouttask)\n* [SSHAgentTask](doc:sshagenttask)\n* [YamlConfigurationTask](doc:yamlconfigurationtask)\n\n### Tasks for deploying a release\n\n* [DeployReleaseTask](doc:deployreleasetask)\n* [ExecuteCommandTask](doc:executecommandtask)\n* [MaintenanceModeTask](doc:maintenancemodetask)\n\n## Creating a task\n\nA task can be either an Event Listener or an Event Subscriber. For reusability it's easier for users to configure a task that is self-aware of the events it needs to listen to than to configure each event listener separately.\n\nFor more information on how to create an Event Subscriber, see the [Symfony documentation][link-symfony-event-dispatcher-event-subscriber].\n\n### Usage of connection adapters\n\nDue to the platform independent nature of Accompli and the ability to remotely install projects, all task should execute through a connection adapter 'middleman'. The connection adapter is retrieved from a Host object which is available either through an Event object or Workspace object (depending on the dispatched Event object).\n\nThe easiest way to ensure you have an active (connected) connection adapter is to extend from the [AbstractConnectedTask][link-accompli-abstract-connected-task] and retrieve the connection adapter by calling `ensureConnection`.\n\n```php\n<?php\n\nnamespace Accompli\\Task;\n\n/**\n * ExampleTask does something with a connection.\n */\nclass ExampleTask extends AbstractConnectedTask\n{\n    /**\n     * {:::at:::inheritdoc}\n     */\n    public static function getSubscribedEvents()\n    {\n        return array(\n            AccompliEvents::PREPARE_WORKSPACE => array(\n                array('onPrepareWorkspaceDoSomething', 0),\n            ),\n        );\n    }\n\n    /**\n     * Do something by using the connection adapter.\n     *\n     * @param WorkspaceEvent $event\n     */\n    public function onPrepareWorkspaceDoSomething(WorkspaceEvent $event)\n    {\n        $connection = $this->ensureConnection($event->getHost());\n\n        // Do something\n    }\n}\n\n```\n\n### Dispatched Accompli events\n\nThe amount of events dispatched depends on the configured deployment strategy. A typical deployment strategy should at least dispatch the events described below.\n\n#### Events dispatched during installation of a release\n\n1. AccompliEvents::CREATE_CONNECTION\n2. AccompliEvents::PREPARE_WORKSPACE\n3. AccompliEvents::PREPARE_RELEASE\n4. AccompliEvents::INSTALL_RELEASE\n5. AccompliEvents::INSTALL_RELEASE_COMPLETE (dispatched only when the installation of a release was completed successfully)\n6. AccompliEvents::INSTALL_RELEASE_FAILED (dispatched only when eg. a certain task fails)\n\n#### Events dispatched during deployment of a release\n\nThe deployment of a release has two scenario's:\n* Deployment of a new release.\n* Rollback to an old release.\n\nSome dispatched events differ per scenario.\n\n##### Deployment of a new release\n\n1. AccompliEvents::CREATE_CONNECTION\n2. AccompliEvents::GET_WORKSPACE\n3. AccompliEvents::PREPARE_DEPLOY_RELEASE\n4. AccompliEvents::DEPLOY_RELEASE\n5. AccompliEvents::DEPLOY_RELEASE_COMPLETE (dispatched only when the deployment of a release was completed successfully)\n6. AccompliEvents::DEPLOY_RELEASE_FAILED  (dispatched only when eg. a certain task fails)\n\n##### Rollback deployment to an old release\n\n1. AccompliEvents::CREATE_CONNECTION\n2. AccompliEvents::GET_WORKSPACE\n3. AccompliEvents::PREPARE_DEPLOY_RELEASE\n4. AccompliEvents::ROLLBACK_RELEASE\n5. AccompliEvents::ROLLBACK_RELEASE_COMPLETE (dispatched only when the deployment of a release was completed successfully)\n6. AccompliEvents::ROLLBACK_RELEASE_FAILED (dispatched only when eg. a certain task fails)\n\nFor more in-depth information on the dispatched events, please see the [AccompliEvents][link-accompli-events-class] class.\n\n[link-symfony-event-dispatcher]: http://symfony.com/doc/current/components/event_dispatcher/introduction.html\n[link-symfony-event-dispatcher-event-subscriber]: http://symfony.com/doc/current/components/event_dispatcher/introduction.html#using-event-subscribers\n[link-accompli-abstract-connected-task]: https://github.com/accompli/accompli/blob/master/src/Task/AbstractConnectedTask.php\n[link-accompli-events-class]: https://github.com/accompli/accompli/blob/master/src/AccompliEvents.php","excerpt":"","slug":"tasks","type":"basic","title":"Tasks"}
A task consists of one or more installation and/or deployment actions. They execute the actions by listening to events dispatched by the [Symfony Event Dispatcher][link-symfony-event-dispatcher] service. ## Available tasks The following tasks are included in Accompli: ### Tasks for installing a release * [ComposerInstallTask](doc:composerinstalltask) * [CreateWorkspaceTask](doc:createworkspacetask) * [ExecuteCommandTask](doc:executecommandtask) * [FilePermissionTask](doc:filepermissiontask) * [RepositoryCheckoutTask](doc:repositorycheckouttask) * [SSHAgentTask](doc:sshagenttask) * [YamlConfigurationTask](doc:yamlconfigurationtask) ### Tasks for deploying a release * [DeployReleaseTask](doc:deployreleasetask) * [ExecuteCommandTask](doc:executecommandtask) * [MaintenanceModeTask](doc:maintenancemodetask) ## Creating a task A task can be either an Event Listener or an Event Subscriber. For reusability it's easier for users to configure a task that is self-aware of the events it needs to listen to than to configure each event listener separately. For more information on how to create an Event Subscriber, see the [Symfony documentation][link-symfony-event-dispatcher-event-subscriber]. ### Usage of connection adapters Due to the platform independent nature of Accompli and the ability to remotely install projects, all task should execute through a connection adapter 'middleman'. The connection adapter is retrieved from a Host object which is available either through an Event object or Workspace object (depending on the dispatched Event object). The easiest way to ensure you have an active (connected) connection adapter is to extend from the [AbstractConnectedTask][link-accompli-abstract-connected-task] and retrieve the connection adapter by calling `ensureConnection`. ```php <?php namespace Accompli\Task; /** * ExampleTask does something with a connection. */ class ExampleTask extends AbstractConnectedTask { /** * {@inheritdoc} */ public static function getSubscribedEvents() { return array( AccompliEvents::PREPARE_WORKSPACE => array( array('onPrepareWorkspaceDoSomething', 0), ), ); } /** * Do something by using the connection adapter. * * @param WorkspaceEvent $event */ public function onPrepareWorkspaceDoSomething(WorkspaceEvent $event) { $connection = $this->ensureConnection($event->getHost()); // Do something } } ``` ### Dispatched Accompli events The amount of events dispatched depends on the configured deployment strategy. A typical deployment strategy should at least dispatch the events described below. #### Events dispatched during installation of a release 1. AccompliEvents::CREATE_CONNECTION 2. AccompliEvents::PREPARE_WORKSPACE 3. AccompliEvents::PREPARE_RELEASE 4. AccompliEvents::INSTALL_RELEASE 5. AccompliEvents::INSTALL_RELEASE_COMPLETE (dispatched only when the installation of a release was completed successfully) 6. AccompliEvents::INSTALL_RELEASE_FAILED (dispatched only when eg. a certain task fails) #### Events dispatched during deployment of a release The deployment of a release has two scenario's: * Deployment of a new release. * Rollback to an old release. Some dispatched events differ per scenario. ##### Deployment of a new release 1. AccompliEvents::CREATE_CONNECTION 2. AccompliEvents::GET_WORKSPACE 3. AccompliEvents::PREPARE_DEPLOY_RELEASE 4. AccompliEvents::DEPLOY_RELEASE 5. AccompliEvents::DEPLOY_RELEASE_COMPLETE (dispatched only when the deployment of a release was completed successfully) 6. AccompliEvents::DEPLOY_RELEASE_FAILED (dispatched only when eg. a certain task fails) ##### Rollback deployment to an old release 1. AccompliEvents::CREATE_CONNECTION 2. AccompliEvents::GET_WORKSPACE 3. AccompliEvents::PREPARE_DEPLOY_RELEASE 4. AccompliEvents::ROLLBACK_RELEASE 5. AccompliEvents::ROLLBACK_RELEASE_COMPLETE (dispatched only when the deployment of a release was completed successfully) 6. AccompliEvents::ROLLBACK_RELEASE_FAILED (dispatched only when eg. a certain task fails) For more in-depth information on the dispatched events, please see the [AccompliEvents][link-accompli-events-class] class. [link-symfony-event-dispatcher]: http://symfony.com/doc/current/components/event_dispatcher/introduction.html [link-symfony-event-dispatcher-event-subscriber]: http://symfony.com/doc/current/components/event_dispatcher/introduction.html#using-event-subscribers [link-accompli-abstract-connected-task]: https://github.com/accompli/accompli/blob/master/src/Task/AbstractConnectedTask.php [link-accompli-events-class]: https://github.com/accompli/accompli/blob/master/src/AccompliEvents.php