You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by to...@apache.org on 2020/07/24 16:55:10 UTC

[couchdb] 01/03: add get_active_job_ids and get_types

This is an automated email from the ASF dual-hosted git repository.

tonysun83 pushed a commit to branch add_active_tasks_fdb2
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 0a444461920c2b95d9ef8ef3c6512ee37f9af351
Author: Tony Sun <to...@gmail.com>
AuthorDate: Fri Jul 24 09:47:09 2020 -0700

    add get_active_job_ids and get_types
    
    We expose get_types in couch_jobs and also add get_active_jobs_ids
    to get the active job ids given a certain type.
---
 src/couch_jobs/src/couch_jobs.erl | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/couch_jobs/src/couch_jobs.erl b/src/couch_jobs/src/couch_jobs.erl
index 88b4bf4..f6fb626 100644
--- a/src/couch_jobs/src/couch_jobs.erl
+++ b/src/couch_jobs/src/couch_jobs.erl
@@ -19,6 +19,8 @@
     remove/3,
     get_job_data/3,
     get_job_state/3,
+    get_active_jobs_ids/2,
+    get_types/1,
 
     % Job processing
     accept/1,
@@ -104,6 +106,23 @@ get_job_state(Tx, Type, JobId) when is_binary(JobId) ->
     end).
 
 
+-spec get_active_jobs_ids(jtx(), job_type()) -> [job_id()] | {error,
+    any()}.
+get_active_jobs_ids(Tx, Type) ->
+    couch_jobs_fdb:tx(couch_jobs_fdb:get_jtx(Tx), fun(JTx) ->
+        Since = couch_jobs_fdb:get_active_since(JTx, Type,
+            {versionstamp, 0, 0}),
+        maps:keys(Since)
+    end).
+
+
+-spec get_types(jtx()) -> [job_type()] | {error, any()}.
+get_types(Tx) ->
+    couch_jobs_fdb:tx(couch_jobs_fdb:get_jtx(Tx), fun(JTx) ->
+        couch_jobs_fdb:get_types(JTx)
+    end).
+
+
 %% Job processor API
 
 -spec accept(job_type()) -> {ok, job(), job_data()} | {error, any()}.