src/pyams_utils/progress.py
branchdev-tf
changeset 408 cf2304af0fab
parent 334 9bb7be798aa6
--- a/src/pyams_utils/progress.py	Wed Nov 20 19:26:23 2019 +0100
+++ b/src/pyams_utils/progress.py	Fri Nov 22 18:51:37 2019 +0100
@@ -10,7 +10,28 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-__docformat__ = 'restructuredtext'
+"""PyAMS_utils.progress module
+
+This module can be used to get progress status on a long running operation.
+
+The process is a s follow:
+
+ - the client generate a "progress ID"; this ID can be any unique ID, and can be generated by
+   MyAMS client library
+ - the client browser send a POST request containg this progress ID to a view
+ - the view calls "init_progress_status(progress_id, request.principal.id, "Task label") when
+   starting it's long operation
+ - during the operation, a call is made regularly to "set_progress_status(progress_id)"; additional
+   arguments can contain a status (to indicate if operation is finished or not), and a simple
+   "message" or two "length" and "current" arguments which can specify the length of the operation
+   and it's current position
+ - at the end of the operation, the view calls "set_progress_status(progress_id, 'finished')" to
+   specify that the operation is finished.
+
+During the whole operation, while waiting for server response, the client browser can send
+requests to "get_progress_status.json", providing the progress ID, to get the operation progress.
+This last operation is done automatically in PyAMS forms.
+"""
 
 from datetime import datetime
 from threading import local
@@ -22,7 +43,10 @@
 from pyams_utils.lock import locked
 
 
-_local = local()
+__docformat__ = 'restructuredtext'
+
+
+_LOCAL = local()
 
 
 PROGRESS_CACHE_NAME = 'PyAMS::progress'
@@ -34,20 +58,20 @@
 def get_tasks_cache():
     """Get cache storing tasks list"""
     try:
-        tasks_cache = _local.running_tasks_cache
+        tasks_cache = _LOCAL.running_tasks_cache
     except AttributeError:
         manager = cache.CacheManager(**cache.cache_regions['persistent'])
-        tasks_cache = _local.running_tasks_cache = manager.get_cache(PROGRESS_CACHE_NAME)
+        tasks_cache = _LOCAL.running_tasks_cache = manager.get_cache(PROGRESS_CACHE_NAME)
     return tasks_cache
 
 
 def get_progress_cache():
     """Get cache storing tasks progress"""
     try:
-        local_cache = _local.progress_cache
+        local_cache = _LOCAL.progress_cache
     except AttributeError:
         manager = cache.CacheManager(**cache.cache_regions['default'])
-        local_cache = _local.progress_cache = manager.get_cache(PROGRESS_CACHE_NAME)
+        local_cache = _LOCAL.progress_cache = manager.get_cache(PROGRESS_CACHE_NAME)
     return local_cache
 
 
@@ -65,6 +89,7 @@
 
 @locked(name=PROGRESS_LOCK_NAME)
 def init_progress_status(progress_id, owner, label, tags=None, length=None, current=None):
+    # pylint: disable=too-many-arguments
     """Initialize progress status for given task
 
     :param str progress_id: task ID