{"action":"created","comment":{"url":"https://api.github.com/repos/doomspork/elixir-school/pulls/comments/58297670","id":58297670,"diff_hunk":"@@ -0,0 +1,93 @@\n+---\n+layout: page\n+title: OTP Супервизоры\n+category: advanced\n+order: 6\n+lang: ru\n+---\n+\n+Супервизоры это специальные процессы с единственной целью: мониторинг других процессов. Супервизоры позволяют нам создавать отказоустойчивые приложения при помощи автоматического перезапуска дочерних процессов в случае их отказа.\n+\n+## Содержание\n+\n+- [Настройка](#section-1)\n+  - [Стратегии](#section-2)\n+  - [Вложенность](#section-3)\n+- [Наблюдатель задач](#section-4)\n+  - [Настройка](#section-5)\n+  - [Наблюдаемые задачи](#section-6)\n+\n+## Настройка\n+\n+Магия супервизоров заключена в функции `Supervisor.start_link/2`.  Помимо запуска нашего супервизора и его потомков, она позволяет нам определять стратегию, которую будет использовать наш супервизор для управления дочерними процессами.\n+\n+Потомки определяются при помощи списка и функции `worker/3`, которую мы импортировали из `Supervisor.Spec`.  Функция `worker/3` принимает модуль, аргументы и набор опций.  Под капотом `worker/3` вызывает `start_link/3` с нашими аргументами во время инициализации.\n+\n+Давайте начнём, используя SimpleQueue из урока [OTP Concurrency](/lessons/advanced/otp-concurrency):\n+\n+```elixir\n+import Supervisor.Spec\n+\n+children = [\n+  worker(SimpleQueue, [], [name: SimpleQueue])\n+]\n+\n+{:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)\n+```\n+\n+Если наш процесс упадёт или завершится, супервизор автоматически перезапустит его как ни в чём не бывало.\n+\n+### Стратегии\n+\n+На данный момент для Супервизора доступны четыре разные стратегии перезапуска:\n+\n++ `:one_for_one` - Перезапуск только упавшего дочернего процесса.\n+\n++ `:one_for_all` - Перезапуск всех дочерних процессов из события падения.\n+\n++ `:rest_for_one` - Перезапуск упавшего процесса и всех процессов, запущенных после него.\n+\n++ `:simple_one_for_one` - Наилучшая для динамически прикрепляемых процессов. Супервизор обязан содержать только одного потомка.\n+\n+### Вложенность\n+\n+Помимо воркеров, мы также можем наблюдать за другими супервизорами, создавая дерево надзора.  Единственное отличие для нас &mdash; замена `supervisor/3` на `worker/3`:\n+\n+```elixir\n+import Supervisor.Spec\n+\n+children = [\n+  supervisor(ExampleApp.ConnectionSupervisor, [[name: ExampleApp.ConnectionSupervisor]]),\n+  worker(SimpleQueue, [[], [name: SimpleQueue]])\n+]\n+\n+{:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)\n+```\n+\n+## Наблюдатель задач\n+\n+Для задач есть свой специальный супервизор &mdash; `Task.Supervisor`.  Он разработан для динамически создаваемых задач и под капотом использует `:simple_one_for_one`.\n+\n+### Настройка\n+\n+Включение `Task.Supervisor` ничем не отличается от других супервизоров:\n+\n+```elixir\n+import Supervisor.Spec\n+\n+children = [\n+  supervisor(Task.Supervisor, [[name: ExampleApp.TaskSupervisor]]),\n+]\n+\n+{:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)\n+```\n+\n+### Наблюдаемые задачи\n+\n+При запущенном супервизоре мы можем использовать функцию `start_child/2` для создания наблюдаемой задачи:\n+\n+```elixir\n+{:ok, pid} = Task.Supervisor.start_child(ExampleApp.TaskSupervisor, fn -> background_work end)\n+```\n+\n+Если наша задача преждевременно упадёт, она будет перезапущена.  Это может быть особенно полезно при работе со входящими соединениями и обработке фоновых задач.","path":"ru/lessons/advanced/otp-supervisors.md","position":93,"original_position":93,"commit_id":"3bf2695b441fc75b369ae774b408766b02ac2792","original_commit_id":"3bf2695b441fc75b369ae774b408766b02ac2792","user":{"login":"brain-geek","id":307982,"avatar_url":"https://avatars.githubusercontent.com/u/307982?v=3","gravatar_id":"","url":"https://api.github.com/users/brain-geek","html_url":"https://github.com/brain-geek","followers_url":"https://api.github.com/users/brain-geek/followers","following_url":"https://api.github.com/users/brain-geek/following{/other_user}","gists_url":"https://api.github.com/users/brain-geek/gists{/gist_id}","starred_url":"https://api.github.com/users/brain-geek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brain-geek/subscriptions","organizations_url":"https://api.github.com/users/brain-geek/orgs","repos_url":"https://api.github.com/users/brain-geek/repos","events_url":"https://api.github.com/users/brain-geek/events{/privacy}","received_events_url":"https://api.github.com/users/brain-geek/received_events","type":"User","site_admin":false},"body":"`упадёт` is a slang term, afaik. What do you think about replacing it with `выйдет из строя`?","created_at":"2016-04-02T18:31:04Z","updated_at":"2016-04-02T18:31:04Z","html_url":"https://github.com/doomspork/elixir-school/pull/239#discussion_r58297670","pull_request_url":"https://api.github.com/repos/doomspork/elixir-school/pulls/239","_links":{"self":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/comments/58297670"},"html":{"href":"https://github.com/doomspork/elixir-school/pull/239#discussion_r58297670"},"pull_request":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/239"}}},"pull_request":{"url":"https://api.github.com/repos/doomspork/elixir-school/pulls/239","id":64365191,"html_url":"https://github.com/doomspork/elixir-school/pull/239","diff_url":"https://github.com/doomspork/elixir-school/pull/239.diff","patch_url":"https://github.com/doomspork/elixir-school/pull/239.patch","issue_url":"https://api.github.com/repos/doomspork/elixir-school/issues/239","number":239,"state":"open","locked":false,"title":"[RU] Added 'advanced/otp-supervisors' lesson translation.","user":{"login":"nscyclone","id":5345029,"avatar_url":"https://avatars.githubusercontent.com/u/5345029?v=3","gravatar_id":"","url":"https://api.github.com/users/nscyclone","html_url":"https://github.com/nscyclone","followers_url":"https://api.github.com/users/nscyclone/followers","following_url":"https://api.github.com/users/nscyclone/following{/other_user}","gists_url":"https://api.github.com/users/nscyclone/gists{/gist_id}","starred_url":"https://api.github.com/users/nscyclone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nscyclone/subscriptions","organizations_url":"https://api.github.com/users/nscyclone/orgs","repos_url":"https://api.github.com/users/nscyclone/repos","events_url":"https://api.github.com/users/nscyclone/events{/privacy}","received_events_url":"https://api.github.com/users/nscyclone/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-28T19:45:47Z","updated_at":"2016-04-02T18:31:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7d7bbb39a8ed2cb8f8e0ec2a1e99b908147bd12c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/doomspork/elixir-school/pulls/239/commits","review_comments_url":"https://api.github.com/repos/doomspork/elixir-school/pulls/239/comments","review_comment_url":"https://api.github.com/repos/doomspork/elixir-school/pulls/comments{/number}","comments_url":"https://api.github.com/repos/doomspork/elixir-school/issues/239/comments","statuses_url":"https://api.github.com/repos/doomspork/elixir-school/statuses/3bf2695b441fc75b369ae774b408766b02ac2792","head":{"label":"nscyclone:ru/advanced/otp-supervisors","ref":"ru/advanced/otp-supervisors","sha":"3bf2695b441fc75b369ae774b408766b02ac2792","user":{"login":"nscyclone","id":5345029,"avatar_url":"https://avatars.githubusercontent.com/u/5345029?v=3","gravatar_id":"","url":"https://api.github.com/users/nscyclone","html_url":"https://github.com/nscyclone","followers_url":"https://api.github.com/users/nscyclone/followers","following_url":"https://api.github.com/users/nscyclone/following{/other_user}","gists_url":"https://api.github.com/users/nscyclone/gists{/gist_id}","starred_url":"https://api.github.com/users/nscyclone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nscyclone/subscriptions","organizations_url":"https://api.github.com/users/nscyclone/orgs","repos_url":"https://api.github.com/users/nscyclone/repos","events_url":"https://api.github.com/users/nscyclone/events{/privacy}","received_events_url":"https://api.github.com/users/nscyclone/received_events","type":"User","site_admin":false},"repo":{"id":54916282,"name":"elixir-school","full_name":"nscyclone/elixir-school","owner":{"login":"nscyclone","id":5345029,"avatar_url":"https://avatars.githubusercontent.com/u/5345029?v=3","gravatar_id":"","url":"https://api.github.com/users/nscyclone","html_url":"https://github.com/nscyclone","followers_url":"https://api.github.com/users/nscyclone/followers","following_url":"https://api.github.com/users/nscyclone/following{/other_user}","gists_url":"https://api.github.com/users/nscyclone/gists{/gist_id}","starred_url":"https://api.github.com/users/nscyclone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nscyclone/subscriptions","organizations_url":"https://api.github.com/users/nscyclone/orgs","repos_url":"https://api.github.com/users/nscyclone/repos","events_url":"https://api.github.com/users/nscyclone/events{/privacy}","received_events_url":"https://api.github.com/users/nscyclone/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nscyclone/elixir-school","description":"Lessons about the Elixir programming language","fork":true,"url":"https://api.github.com/repos/nscyclone/elixir-school","forks_url":"https://api.github.com/repos/nscyclone/elixir-school/forks","keys_url":"https://api.github.com/repos/nscyclone/elixir-school/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nscyclone/elixir-school/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nscyclone/elixir-school/teams","hooks_url":"https://api.github.com/repos/nscyclone/elixir-school/hooks","issue_events_url":"https://api.github.com/repos/nscyclone/elixir-school/issues/events{/number}","events_url":"https://api.github.com/repos/nscyclone/elixir-school/events","assignees_url":"https://api.github.com/repos/nscyclone/elixir-school/assignees{/user}","branches_url":"https://api.github.com/repos/nscyclone/elixir-school/branches{/branch}","tags_url":"https://api.github.com/repos/nscyclone/elixir-school/tags","blobs_url":"https://api.github.com/repos/nscyclone/elixir-school/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nscyclone/elixir-school/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nscyclone/elixir-school/git/refs{/sha}","trees_url":"https://api.github.com/repos/nscyclone/elixir-school/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nscyclone/elixir-school/statuses/{sha}","languages_url":"https://api.github.com/repos/nscyclone/elixir-school/languages","stargazers_url":"https://api.github.com/repos/nscyclone/elixir-school/stargazers","contributors_url":"https://api.github.com/repos/nscyclone/elixir-school/contributors","subscribers_url":"https://api.github.com/repos/nscyclone/elixir-school/subscribers","subscription_url":"https://api.github.com/repos/nscyclone/elixir-school/subscription","commits_url":"https://api.github.com/repos/nscyclone/elixir-school/commits{/sha}","git_commits_url":"https://api.github.com/repos/nscyclone/elixir-school/git/commits{/sha}","comments_url":"https://api.github.com/repos/nscyclone/elixir-school/comments{/number}","issue_comment_url":"https://api.github.com/repos/nscyclone/elixir-school/issues/comments{/number}","contents_url":"https://api.github.com/repos/nscyclone/elixir-school/contents/{+path}","compare_url":"https://api.github.com/repos/nscyclone/elixir-school/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nscyclone/elixir-school/merges","archive_url":"https://api.github.com/repos/nscyclone/elixir-school/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nscyclone/elixir-school/downloads","issues_url":"https://api.github.com/repos/nscyclone/elixir-school/issues{/number}","pulls_url":"https://api.github.com/repos/nscyclone/elixir-school/pulls{/number}","milestones_url":"https://api.github.com/repos/nscyclone/elixir-school/milestones{/number}","notifications_url":"https://api.github.com/repos/nscyclone/elixir-school/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nscyclone/elixir-school/labels{/name}","releases_url":"https://api.github.com/repos/nscyclone/elixir-school/releases{/id}","deployments_url":"https://api.github.com/repos/nscyclone/elixir-school/deployments","created_at":"2016-03-28T19:01:34Z","updated_at":"2016-03-28T19:01:35Z","pushed_at":"2016-04-01T13:20:18Z","git_url":"git://github.com/nscyclone/elixir-school.git","ssh_url":"git@github.com:nscyclone/elixir-school.git","clone_url":"https://github.com/nscyclone/elixir-school.git","svn_url":"https://github.com/nscyclone/elixir-school","homepage":"https://elixirschool.com","size":832,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"doomspork:master","ref":"master","sha":"aa8471a7d70bd0c5ac390cc9418a00c1a4f9652a","user":{"login":"doomspork","id":73386,"avatar_url":"https://avatars.githubusercontent.com/u/73386?v=3","gravatar_id":"","url":"https://api.github.com/users/doomspork","html_url":"https://github.com/doomspork","followers_url":"https://api.github.com/users/doomspork/followers","following_url":"https://api.github.com/users/doomspork/following{/other_user}","gists_url":"https://api.github.com/users/doomspork/gists{/gist_id}","starred_url":"https://api.github.com/users/doomspork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doomspork/subscriptions","organizations_url":"https://api.github.com/users/doomspork/orgs","repos_url":"https://api.github.com/users/doomspork/repos","events_url":"https://api.github.com/users/doomspork/events{/privacy}","received_events_url":"https://api.github.com/users/doomspork/received_events","type":"User","site_admin":false},"repo":{"id":36616176,"name":"elixir-school","full_name":"doomspork/elixir-school","owner":{"login":"doomspork","id":73386,"avatar_url":"https://avatars.githubusercontent.com/u/73386?v=3","gravatar_id":"","url":"https://api.github.com/users/doomspork","html_url":"https://github.com/doomspork","followers_url":"https://api.github.com/users/doomspork/followers","following_url":"https://api.github.com/users/doomspork/following{/other_user}","gists_url":"https://api.github.com/users/doomspork/gists{/gist_id}","starred_url":"https://api.github.com/users/doomspork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doomspork/subscriptions","organizations_url":"https://api.github.com/users/doomspork/orgs","repos_url":"https://api.github.com/users/doomspork/repos","events_url":"https://api.github.com/users/doomspork/events{/privacy}","received_events_url":"https://api.github.com/users/doomspork/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/doomspork/elixir-school","description":"Lessons about the Elixir programming language","fork":false,"url":"https://api.github.com/repos/doomspork/elixir-school","forks_url":"https://api.github.com/repos/doomspork/elixir-school/forks","keys_url":"https://api.github.com/repos/doomspork/elixir-school/keys{/key_id}","collaborators_url":"https://api.github.com/repos/doomspork/elixir-school/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/doomspork/elixir-school/teams","hooks_url":"https://api.github.com/repos/doomspork/elixir-school/hooks","issue_events_url":"https://api.github.com/repos/doomspork/elixir-school/issues/events{/number}","events_url":"https://api.github.com/repos/doomspork/elixir-school/events","assignees_url":"https://api.github.com/repos/doomspork/elixir-school/assignees{/user}","branches_url":"https://api.github.com/repos/doomspork/elixir-school/branches{/branch}","tags_url":"https://api.github.com/repos/doomspork/elixir-school/tags","blobs_url":"https://api.github.com/repos/doomspork/elixir-school/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/doomspork/elixir-school/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/doomspork/elixir-school/git/refs{/sha}","trees_url":"https://api.github.com/repos/doomspork/elixir-school/git/trees{/sha}","statuses_url":"https://api.github.com/repos/doomspork/elixir-school/statuses/{sha}","languages_url":"https://api.github.com/repos/doomspork/elixir-school/languages","stargazers_url":"https://api.github.com/repos/doomspork/elixir-school/stargazers","contributors_url":"https://api.github.com/repos/doomspork/elixir-school/contributors","subscribers_url":"https://api.github.com/repos/doomspork/elixir-school/subscribers","subscription_url":"https://api.github.com/repos/doomspork/elixir-school/subscription","commits_url":"https://api.github.com/repos/doomspork/elixir-school/commits{/sha}","git_commits_url":"https://api.github.com/repos/doomspork/elixir-school/git/commits{/sha}","comments_url":"https://api.github.com/repos/doomspork/elixir-school/comments{/number}","issue_comment_url":"https://api.github.com/repos/doomspork/elixir-school/issues/comments{/number}","contents_url":"https://api.github.com/repos/doomspork/elixir-school/contents/{+path}","compare_url":"https://api.github.com/repos/doomspork/elixir-school/compare/{base}...{head}","merges_url":"https://api.github.com/repos/doomspork/elixir-school/merges","archive_url":"https://api.github.com/repos/doomspork/elixir-school/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/doomspork/elixir-school/downloads","issues_url":"https://api.github.com/repos/doomspork/elixir-school/issues{/number}","pulls_url":"https://api.github.com/repos/doomspork/elixir-school/pulls{/number}","milestones_url":"https://api.github.com/repos/doomspork/elixir-school/milestones{/number}","notifications_url":"https://api.github.com/repos/doomspork/elixir-school/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/doomspork/elixir-school/labels{/name}","releases_url":"https://api.github.com/repos/doomspork/elixir-school/releases{/id}","deployments_url":"https://api.github.com/repos/doomspork/elixir-school/deployments","created_at":"2015-05-31T18:27:42Z","updated_at":"2016-04-01T08:14:11Z","pushed_at":"2016-04-01T21:01:09Z","git_url":"git://github.com/doomspork/elixir-school.git","ssh_url":"git@github.com:doomspork/elixir-school.git","clone_url":"https://github.com/doomspork/elixir-school.git","svn_url":"https://github.com/doomspork/elixir-school","homepage":"https://elixirschool.com","size":937,"stargazers_count":346,"watchers_count":346,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":100,"mirror_url":null,"open_issues_count":43,"forks":100,"open_issues":43,"watchers":346,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/239"},"html":{"href":"https://github.com/doomspork/elixir-school/pull/239"},"issue":{"href":"https://api.github.com/repos/doomspork/elixir-school/issues/239"},"comments":{"href":"https://api.github.com/repos/doomspork/elixir-school/issues/239/comments"},"review_comments":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/239/comments"},"review_comment":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/239/commits"},"statuses":{"href":"https://api.github.com/repos/doomspork/elixir-school/statuses/3bf2695b441fc75b369ae774b408766b02ac2792"}}}}