LoginSignup
3
3

More than 5 years have passed since last update.

Supervisorメモ(完全に自分用) #Erlang

Last updated at Posted at 2015-08-06

公式ドキュメント

shutdown

-type shutdown() :: brutal_kill | timeout().

brutal_kill

直ぐに kill
erlang
exit(Child, kill)

Timeout::integer()

  1. exit(Child, shutdown)
  2. (Timeoutミリ秒待つ)
  3. exit(Child, kill)

infinity

ずっと待つ

子プロセスがSupervisorの場合、 infinity で良い。
子プロセスがWorkerの場合は気を付けなければならない


ChildSpecをmapで指定しshutdownを省略した場合のデフォルト値は
1. typeが worker の場合は 5000
2. typeが supervisor の場合は infinity

supervisor:terminate_child/2

-spec terminate_child(SupRef, Id) -> Result when
    SupRef :: supervisor:sup_ref(),
    Id :: pid() | supervisor:child_id(),
    Result :: ok | {error, Error},
    Error :: not_found | simple_one_for_one.

この関数を実行すると、 shutdown の指定に従って停止される。

Id の値は simple_one_for_one 以外 の場合は supervisor:child_id() (not pid() )、
( pid() を指定すると {error, not_found} が返る)
simple_one_for_one の場合は pid() を指定する
( supervisor:child_id() を指定すると {error, simple_one_for_one} が返る)
(エラーの内容が対称的ではないのが悲しい…)

simple_one_for_one の停止

simple_one_for_one のSupervisorで子プロセスを停止させる場合は supervisor:terminate_child(SupRef, Id). を実行する。

この場合の Idpid() しか使えない。
child_id() (のようなもの)を使おうとすると {error, simple_one_for_one} が変える。)

simple_one_for_one の場合は supervisor:terminate_child(SupRef, Id) した時点でSupervisorからChildSpecが削除される
:left_right_arrow: supervisor:delete_child(SupRef, Id) を呼ぶ必要がない)
(ちなみに、delete_childの Id はterminate_childの Id::pid()|supervisor:child_id() と違い Id::child_id() である。 simple_one_for_one の時に terminate_childdelete_child のどっちを呼んだらいいか迷った時はこの辺りをイメージしてみればわかるかもしれない(逆もまた然り))

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3