|
erlang开发 要手动去c:l() 改动的模块。 弄个自动加载的mod 提高开发效率
- -module('_reload_beam').
- %% --------------------------------------------------------------------
- %% Include files
- %% --------------------------------------------------------------------
- -include("comm.lib.hrl").
- -include("mod.db.hrl").
- -include_lib("kernel/include/file.hrl").
- %% ====================================================================
- %% API functions
- %% ====================================================================
- -export([do/0]).
-
- %% @author [email protected]
- %% @用法: 每秒调用 _reload_beam:do() 一次,自动检查是否有文件更新并加载
- %% 1.生产环境 每239秒检查一次
- %% 2.开发环境 每秒检查一次 (默认)
- do() ->
- case filelib:is_file("/data/game_server/release.txt") of
- ?true -> %% 生产环境(条件可以自己定义)
- NKEY = {?MODULE,'_reload_do_'},
- NTime = util_time:seconds(),
- case ets:lookup(?ETS_S_CONFIG,NKEY) of
- [{_,OTime}|_] ->
- ?IF(NTime - OTime > 239, begin do2(), ets:insert(?ETS_S_CONFIG, {NKEY, NTime}) end, ?skip);
- [] ->
- ets:insert(?ETS_S_CONFIG, {NKEY, NTime});
- _ ->
- ?skip
- end;
- ?false -> %% 开发环境
- do2()
- end.
-
- do2() ->
- [case file:read_file_info(Filename) of
- {ok, #file_info{mtime = Mtime}} ->
- case ets:lookup(?ETS_S_CONFIG,{?MODULE,Module}) of
- [{_,OTime}|_] ->
- ?IF(Mtime > OTime, reload(Module,Mtime), ?skip);
- [] ->
- ets:insert(?ETS_S_CONFIG, {{?MODULE,Module}, Mtime});
- _ -> ?skip
- end;
- {?ok, _ } -> ?skip;
- {?error, enoent} -> ?skip;
- {?error, Reason} ->
- ?MSG_ERROR("Error reading ~s's file info: ~p~n",[Filename, Reason]),
- ?error
- end || {Module, Filename} <- code:all_loaded(), is_list(Filename)].
- reload(Module,Mtime)->
- c:l(Module),
- ets:insert(?ETS_S_CONFIG, {{?MODULE,Module},Mtime}),
- ?MSG_ECHO("Reloading ~p reload ok[code] test ok!",[Module]).
复制代码
|
|