Update the task if any props change This ignores the frequency setting and just updates forcefully on any change to the task properties.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/296b98a4 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/296b98a4 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/296b98a4 Branch: refs/heads/windsor-merge Commit: 296b98a4dc09679375424bbd5ac53224808fcbcd Parents: fdbf505 Author: Paul J. Davis <[email protected]> Authored: Tue Aug 12 15:42:35 2014 -0500 Committer: Robert Newson <[email protected]> Committed: Tue Aug 26 10:44:12 2014 +0100 ---------------------------------------------------------------------- src/couch_task_status.erl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/296b98a4/src/couch_task_status.erl ---------------------------------------------------------------------- diff --git a/src/couch_task_status.erl b/src/couch_task_status.erl index 8a8dbf2..8adba6b 100644 --- a/src/couch_task_status.erl +++ b/src/couch_task_status.erl @@ -68,9 +68,14 @@ set_update_frequency(Msecs) -> update(Props) -> MergeProps = lists:ukeysort(1, Props), - TaskProps = lists:ukeymerge(1, MergeProps, erlang:get(task_status_props)), - put(task_status_props, TaskProps), - maybe_persist(TaskProps). + CurrProps = erlang:get(task_status_props), + TaskProps = lists:ukeymerge(1, MergeProps, CurrProps), + case TaskProps == CurrProps of + true -> + maybe_persist(TaskProps); + false -> + persist(TaskProps) + end. get(Props) when is_list(Props) -> @@ -81,18 +86,22 @@ get(Prop) -> couch_util:get_value(Prop, TaskProps). -maybe_persist(TaskProps0) -> +maybe_persist(TaskProps) -> {LastUpdateTime, Frequency} = erlang:get(task_status_update), case timer:now_diff(Now = os:timestamp(), LastUpdateTime) >= Frequency of true -> put(task_status_update, {Now, Frequency}), - TaskProps = ?set(TaskProps0, updated_on, timestamp(Now)), - gen_server:cast(?MODULE, {update_status, self(), TaskProps}); + persist(TaskProps); false -> ok end. +persist(TaskProps0) -> + TaskProps = ?set(TaskProps0, updated_on, timestamp(os:timestamp())), + gen_server:cast(?MODULE, {update_status, self(), TaskProps}). + + init([]) -> % read configuration settings and register for configuration changes ets:new(?MODULE, [ordered_set, protected, named_table]),
