Erlang workflow
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.
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:
console:
dev/etorrent-dev/bin/etorrent console \
-pa ../../apps/etorrent/ebin
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, run make
again and so on. When you are satisfied with your change, you go into the console (erlang shell) and execute l(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.
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.
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!
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.
精彩评论