Erlang工作流程
你如何组织你的 erlang 工作流程?我现在正在学习一些 Erlang,并且正在使用 Rebar,重新编译、重建并重新启动整个版本(我正在每次编辑后都试图保持 OTP'ish)。我很确定有一种更聪明的方法可以做到这一点。
How do you organize your erlang workflow? I'm learning some Erlang now and I'm using Rebar, recompiling, rebuilding and restarting an entire release (I'm trying to keep things OTP'ish) after each edit. I'm pretty sure that there is a smarter way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Etorrent 中,我使用了一个你可能喜欢的小技巧:
当你构建了一个开发版本时,你可以执行命令
make console
,它具有以下定义:基本上,它在大多数情况下使用版本 ebins东西,但覆盖应用程序 ebin 位于您通常构建软件的位置之外。现在,运行控制台,您可以编辑代码、运行
make
(我在 Emacs 中按下组合键)、修复错误、再次运行make
等等。当您对更改感到满意时,您可以进入控制台(erlang shell)并执行l(ModuleToLoad)
,此时正在运行的系统将注入新代码。 OTP 将自动获取热部署的代码更改并更改流程。本质上,您在处理代码时只需很少重新启动即可。现在,我们也有测试,所以如果你想更多地保证新代码的工作,你可以在 etorrent 中执行
make test
,让测试框架在注入之前在新形成的代码上运行。In Etorrent, I am using a little trick you may like:
When you have built a development release, you can execute the command
make console
which has the following definition:basically, it uses the release ebins for most stuff, but overrides the application ebin to be outside at the point where you normally build the software. Now, running a console, you can edit your code, run
make
(I hit a key combination in Emacs), fix errors, runmake
again and so on. When you are satisfied with your change, you go into the console (erlang shell) and executel(ModuleToLoad)
at which point the running system gets the new code injected. OTP will automatically pick up the hot-deployed code change and alter the processes. Essentially you only have to restart fairly rarely when working on the code.Nowadays, we also have tests, so you can execute
make test
in etorrent to have the test framework run on your newly formed code before injection if you want a bit more guarantee that the new code works.使用 Chicago Boss,您只需在网络浏览器中点击“刷新”即可:
http://www.chicagoboss.org/
即使您的目标不是 Web 开发,这也可能是一种比您当前的工作流程更有趣的学习 Erlang 的方法。 CB 在浏览器中漂亮地打印编译和运行时错误。
With Chicago Boss you just hit "Refresh" in your web browser:
http://www.chicagoboss.org/
Even if your goal isn't web development, it might be a way to learn Erlang that is more fun than your current workflow. CB pretty-prints compilation and run-time errors right in the browser.
我一直在使用 Sync 来避免可怕的编辑/重新编译/重新启动循环。它监视源文件的更改,然后仅重新编译并重新加载更改的模块。它将错误和警告打印到控制台,并将它们发送到通知发送/咆哮(如果可用)。
就像运行
sync:go() 一样简单。
看看这个钢筋模板 以获得更好的示例。
如果您正在集群上进行开发,另一个很棒的功能是同步的“补丁模式”。使用“补丁模式”,每次同步成功编译模块时,它都会将编译后的代码发送到连接到集群的每个节点并重新加载模块!
I have been using Sync to avoid the dreaded edit/recompile/restart loop. It watches for changes to your source files then recompiles and reloads only the changed module. It prints errors and warnings to the console and sends them to notify-send/growl if available.
It's as easy as running
sync:go().
Take a look at this rebar template for a better example.
If you are developing on a cluster another great feature is sync's "patch mode". With "patch mode" every time sync successfully compiles a module it sends the compiled code to every node connected to the cluster and reloads the module!
要在每次编辑时自动重新加载 src 文件,您可以尝试 rebar3 中的自动插件。
我最近转向了 rebar3,发现它比 rebar 更容易使用。
For automatic reloading of src files with each edit, You can try auto plugin in rebar3.
I have recently moved to rebar3 and found it to have much easier to work with compared to rebar.