summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Sun <tony.sun427@gmail.com>2020-07-23 17:49:42 -0700
committerTony Sun <tony.sun427@gmail.com>2020-07-23 17:49:42 -0700
commit26784365fc48fb38dfed21db3c7c919cc5866ab1 (patch)
tree0e6d27c7f1289094e0b2f1646044dfbd1470e1b4
parent24f484a46a8a1a7b9756fea319e954b45260ee5f (diff)
downloadcouchdb-26784365fc48fb38dfed21db3c7c919cc5866ab1.tar.gz
use filtermap
-rw-r--r--src/fabric/src/fabric2_active_tasks.erl28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/fabric/src/fabric2_active_tasks.erl b/src/fabric/src/fabric2_active_tasks.erl
index 58157d4d2..fdf7d7b13 100644
--- a/src/fabric/src/fabric2_active_tasks.erl
+++ b/src/fabric/src/fabric2_active_tasks.erl
@@ -1,3 +1,16 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
-module(fabric2_active_tasks).
@@ -17,19 +30,22 @@ get_active_tasks() ->
Types = couch_jobs:get_types(JTx),
lists:foldl(fun(Type, TaskAcc) ->
JobIds = couch_jobs:get_active_jobs_ids(JTx, Type),
- Tasks = lists:map(fun(JobId) ->
+ Tasks = lists:filtermap(fun(JobId) ->
{ok, Data} = couch_jobs:get_job_data(JTx, Type, JobId),
- maps:get(?ACTIVE_TASK_INFO, Data #{})
+ case maps:get(?ACTIVE_TASK_INFO, Data, not_found) of
+ not_found -> false;
+ Info -> {true, Info}
+ end
end, JobIds),
TaskAcc ++ Tasks
end, [], Types)
end).
-update_active_task_info(JobData, ActiveTaskInfo) ->
- JobData#{?ACTIVE_TASK_INFO => ActiveTaskInfo}.
-
-
get_active_task_info(JobData) ->
#{?ACTIVE_TASK_INFO:= ActiveTaskInfo} = JobData,
ActiveTaskInfo.
+
+
+update_active_task_info(JobData, ActiveTaskInfo) ->
+ JobData#{?ACTIVE_TASK_INFO => ActiveTaskInfo}. \ No newline at end of file