Commits

Anonymous committed 71ee4ef

Wiring up js_source_dir to JS VM initialization. Cleaning up some dangling whitespace in riak_sup.erl

Comments (0)

Files changed (3)

apps/riak/src/riak_js_vm.erl

     js_driver:new(InitFun).
 
 init_context(Ctx) ->
-    case load_init_source() of
-        {ok, Source} ->
-            js:define(Ctx, Source);
-        {error, Error} ->
-            {error, Error}
-    end.
+    load_user_builtins(Ctx),
+    load_mapred_builtins(Ctx).
 
 priv_dir() ->
     %% Hacky workaround to handle running from a standard app directory
             Dir
     end.
 
-load_init_source() ->
-    case js_cache:fetch("mapred_builtins") of
-        none ->
-            {ok, Contents} = file:read_file(filename:join([priv_dir(), "mapred_builtins.js"])),
-            js_cache:store("mapred_builtins", Contents),
-            {ok, Contents};
-        Contents ->
-            {ok, Contents}
+load_user_builtins(Ctx) ->
+    case riak:get_app_env(js_source_dir, undefined) of
+        undefined ->
+            ok;
+        Path ->
+            Files = filelib:wildcard("*.js", Path),
+            lists:foreach(fun(File) ->
+                                  {ok, Contents} = file:read_file(filename:join([Path, File])),
+                                  js:define(Ctx, Contents) end, Files)
     end.
 
+load_mapred_builtins(Ctx) ->
+    {ok, Contents} = file:read_file(filename:join([priv_dir(), "mapred_builtins.js"])),
+    js:define(Ctx, Contents).
+
 jsonify_object({error, notfound}=Obj) ->
     {struct, [Obj]};
 jsonify_object(Obj) ->

apps/riak/src/riak_sup.erl

         VSup,
         ?IF(HasStorageBackend, VMaster, []),
         HandoffListen,
-        RingMgr, 
-        Connect, 
+        RingMgr,
+        Connect,
         LocalLogger,
         ?IF(IsWebConfigured, RiakWeb, []),
         ?IF(IsStatEnabled, RiakStat, []),

rel/overlay/etc/app.config

          %% 8 is a good default for smaller installations. A larger number like
          %% 12 or 16 is appropriate for installations handling lots of map/reduce
          %% processing.
-         {jsvm_count, 8}
+         {jsvm_count, 8},
+
+         %% js_source_dir should point to a directory containing Javascript source
+         %% files which will be loaded by Riak when it initializes Javascript VMs.
+         %{js_source_dir, "/tmp/js_source"}
+
         ]},
 
  %% SASL config