public
Fork of KirinDave/fuzed
Description: A new revision of Fuzed, the Erlang-based frontend for web apps. Check out the mailing list at http://groups.google.com/group/fuzed
Clone URL: git://github.com/tmm1/fuzed.git
Working on a better, more configurable frontnet.\n I can't help but wonder 
if maybe going back to the config file was a smarter idea tho.
KirinDave (author)
Sun May 25 16:40:09 -0700 2008
commit  aa1bf85d30bc31f7be87b7d2ccb3d560daa18ad1
tree    013e6f1c97b917a08db983e6b03c8d33ee4864ee
parent  0f6b09930784a37191dea47fb2b19559e192e657
...
5
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
5
6
7
 
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
0
@@ -5,4 +5,28 @@
0
 % This responder can modify the request, and is obligated to return
0
 % a pool and the request. You can just return it directly if you want.
0
 provide_pool(A, _GC, _SC) ->
0
- {resource_fountain:best_pool_for_details_match(details()), A}.
0
+ % I confess this approach is lazy, but I don't think it's slow.
0
+ case application:get_env(fuzed_frontend, current_pool) of
0
+ undefined ->
0
+ Pool = lookup_and_cache_pool(),
0
+ {Pool, A};
0
+ {ok, Pool} ->
0
+ case is_remote_process_alive(Pool) of
0
+ true ->
0
+ {Pool, A};
0
+ false ->
0
+ {lookup_and_cache_pool(), A}
0
+ end
0
+ end.
0
+
0
+lookup_and_cache_pool() ->
0
+ Pool = resource_fountain:best_pool_for_details_match(details()),
0
+ application:set_env(fuzed_frontend, current_pool, Pool),
0
+ Pool.
0
+
0
+is_remote_process_alive(Pid) ->
0
+ Node = node(Pid),
0
+ case rpc:call(Node, erlang, is_process_alive, [Pid]) of
0
+ {badrpc, _Reason} -> false;
0
+ Result -> Result
0
+ end.
...
4
5
6
7
 
8
9
 
 
 
 
10
 
11
12
13
...
27
28
29
30
 
 
31
32
33
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
4
5
6
 
7
8
 
9
10
11
12
13
14
15
16
17
...
31
32
33
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
0
@@ -4,10 +4,14 @@
0
 
0
 
0
 setup(Port, DocRoot, Responder) ->
0
- yaws_begin_server(yaws_global_configs(Port, DocRoot, Responder)).
0
+ yaws_begin_server(yaws_global_configs(Port, DocRoot, Responder, [])).
0
 
0
-yaws_global_configs(Port, DocRoot, Responder) ->
0
+setup(Port, DocRoot, Responder, AppMods) ->
0
+ yaws_begin_server(yaws_global_configs(Port, DocRoot, Responder, AppMods)).
0
+
0
+yaws_global_configs(Port, DocRoot, Responder, AppMods) ->
0
   Y = yaws_config:yaws_dir(),
0
+ {AppModModules, Opaques} = prepare_appmod_data(AppMods),
0
   GC = #gconf{yaws_dir = Y,
0
               ebin_dir = [],
0
               include_dir = [],
0
@@ -27,10 +31,25 @@ yaws_global_configs(Port, DocRoot, Responder) ->
0
               listen = {0,0,0,0},
0
               docroot = DocRoot,
0
               errormod_404 = Responder,
0
- appmods = []},
0
+ appmods = AppModModules,
0
+ opaque = Opaques},
0
   {GC,SC}.
0
 
0
 yaws_begin_server({GC,SC}) ->
0
   application:set_env(yaws, embedded, true),
0
   application:start(yaws),
0
   yaws_api:setconf(GC, [[SC]]).
0
+
0
+% Triples: {Path, module, Role}
0
+prepare_appmod_data(AppMods) when is_list(AppMods) ->
0
+ lists:foldl(fun({Path, Module, Role}, {AMMM, Opaques}) ->
0
+ {[{Path, Module}|AMMM],
0
+ [{{Path, Module}, [{<<"roles">>, [to_binary(Role)]}]}|Opaques]}
0
+ end,
0
+ {[], []},
0
+ AppMods);
0
+prepare_appmod_data(_) -> {[], []}.
0
+
0
+to_binary(String) when is_list(String) -> list_to_binary(String);
0
+to_binary(Atom) when is_atom(Atom) -> to_binary(atom_to_list(Atom));
0
+to_binary(Binary) when is_binary(Binary) -> Binary.
...
22
23
24
 
25
26
27
...
29
30
31
32
 
33
34
35
...
60
61
62
 
 
...
22
23
24
25
26
27
28
...
30
31
32
 
33
34
35
36
...
61
62
63
64
65
0
@@ -22,6 +22,7 @@ init([]) ->
0
   Master = application:get_env(master),
0
   {ok, DocRoot} = application:get_env(docroot),
0
   {ok, Port} = application:get_env(port),
0
+ AppModSpecs = process_appmods(application:get_env(appmods)),
0
   ResponderModule = figure_responder(),
0
   case Master of
0
     {ok, MasterNode} ->
0
@@ -29,7 +30,7 @@ init([]) ->
0
     undefined ->
0
       MasterNode = node()
0
   end,
0
- frontend_yaws:setup(Port, DocRoot, ResponderModule),
0
+ frontend_yaws:setup(Port, DocRoot, ResponderModule, AppModSpecs),
0
   {ok, {{one_for_one, 10, 600},
0
         [{master_beater,
0
           {master_beater, start_link, [MasterNode, ?GLOBAL_TIMEOUT, ?SLEEP_CYCLE]},
0
@@ -60,3 +61,5 @@ figure_responder() ->
0
     undefined -> frontend_responder
0
   end.
0
       
0
+process_appmods(undefined) -> [];
0
+process_appmods({ok, V}) -> V.
...
1
 
2
3
 
4
5
 
...
 
1
2
 
3
4
 
5
0
@@ -1,5 +1,5 @@
0
-bin/fuzed start -n master@volcano.local
0
+bin/fuzed start -n master@chisai.local
0
 
0
-bin/fuzed frontend -z volcano.local -r test/app/public -s 'kind=rails|roles=production' -n f1@volcano.local
0
+bin/fuzed frontend -z chisai.local -r test/app/public -s 'kind=rails|roles=production' -n f1@chisai.local
0
 
0
-bin/fuzed join -z volcano.local -f rlibs/rails_node.rb -n n1@volcano.local -p
0
+bin/fuzed join -z chisai.local -f rlibs/rails_node.rb -n n1@chisai.local -p

Comments

    No one has commented yet.