Skip to content

Commit

Permalink
Make dispatch rule reloading more stable.
Browse files Browse the repository at this point in the history
When reloading dispatch rules, crash when there is a syntax error, and
keep the old dispatch rules in this case.

Also show a warning to the user in the admin, and do it only once when
hitting the "reload modules" button, not twice.

Fixes issue 117
  • Loading branch information
Arjan Scherpenisse committed Feb 26, 2011
1 parent 3cc18cb commit 5136f11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -39,6 +39,5 @@ render_action(TriggerId, TargetId, Args, Context) ->
%% @spec event(Event, Context1) -> Context2
event({postback, {module_rescan, Actions}, _TriggerId, _TargetId}, Context) ->
z_notifier:notify(module_ready, Context),
z_dispatcher:reload(Context),
Context1 = z_render:growl("Module rescan is in progress.", Context),
z_render:wire(Actions, Context1).
10 changes: 8 additions & 2 deletions src/support/z_dispatcher.erl
Expand Up @@ -221,7 +221,13 @@ code_change(_OldVsn, State, _Extra) ->

%% @doc Reload the dispatch list and send it to the webmachine dispatcher.
reload_dispatch_list(#state{context=Context} = State) ->
DispatchList = collect_dispatch_lists(Context),
DispatchList = try
collect_dispatch_lists(Context)
catch
_:{error, Msg} ->
z_session_manager:broadcast(#broadcast{type="error", message="Dispatch error! " ++ Msg, title="Dispatcher", stay=false}, Context),
State#state.dispatchlist
end,
LookupDict = dispatch_for_uri_lookup(DispatchList),
State#state{dispatchlist=DispatchList, lookup=LookupDict}.

Expand Down Expand Up @@ -271,7 +277,7 @@ get_file_dispatch(File) ->
catch
M:E ->
?ERROR("File dispatch error: ~p ~p", [File, {M,E}]),
[]
throw({error, "Parse error in " ++ z_convert:to_list(File)})
end.


Expand Down

0 comments on commit 5136f11

Please sign in to comment.