何时使用erlang application:start或included_applications和主管? [英] When to use erlang application:start or included_applications and a supervisor?

查看:217
本文介绍了何时使用erlang application:start或included_applications和主管?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Erlang应用程序,它的deps目录中有另一个应用程序.

I have an Erlang application which has a dependency in its deps directory on another application.

据我了解,我可以;

a)通过调用application:start(some_other_app)从包含的应用程序中启动我的依赖应用程序,该程序将启动应用程序并显示其在Observer中独立运行.

a) start my dependent application from my including application by calling application:start(some_other_app) which starts the application and shows it running standalone within Observer.

b)将我的从属应用程序与{included_applications,[some_other_app]}一起包含在我的.app文件中,以便加载该应用程序并且不启动该应用程序,然后从我自己的顶级主管启动包含的应用程序.这将再次启动包含的应用程序,并在Observer中我自己的监视层次结构下显示其运行情况.

b) include my dependent application in my .app file with {included_applications, [some_other_app]} so that the application is loaded and not started and then start the included application from my own top level supervisor. This again starts the included application and shows its running below my own supervision hierarchy in Observer.

我的问题是什么时候应该使用这两种方法?如果我使用选项"a"并且我的从属应用程序退出,它将重新启动还是应该使用方法"b",以便对我所拥有的任何依存关系进行相应的监视?

My question is when should I use either approach? If I use option "a" and my dependent application exits will it be restarted or should I be using approach "b" so that any dependencies I have are monitored accordingly?

在旁注中,我使用Rebar打包和管理我的依赖项.

On a side note I use Rebar to package and manage my dependencies.

谢谢

安迪.

推荐答案

必须在应用程序描述符中声明依赖项,因此在大多数情况下都应使用选项B.

Having your dependencies declared in your application descriptor is the way to go, so you should use option B in most of the scenarios.

在启动应用程序之前,应用程序控制器将确保所有依赖项都存在并已启动(按顺序),并且如果这些依赖项因错误而终止,则还将使您的应用程序失败.此外,应用程序控制器将在需要时关闭所有程序.

The application controller will ensure that all your dependencies are present and started (in order) before starting your application and will also make your app fail if those terminate with errors. Also, the application controller will shutdown everything when needed.

除此之外,如果选择选项A,则在使用application:start/1启动应用程序时,默认情况下将获得一个临时应用程序,因此应使用application:start/2,将永久性原子作为第二个论点.

Other than that, if you choose option A, when starting an application with application:start/1, you will get a temporary application by default, so you should use application:start/2, passing the permanent atom as the second argument.

在应用程序描述符中使用依赖项还有助于提高可见性,无需扫描源代码就很容易了解您的部门.

Having your dependencies in the application descriptor also helps visibility, it's easy to know your deps without scanning the source code.

这篇关于何时使用erlang application:start或included_applications和主管?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆