Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
lmc-base-classes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
LOFAR2.0
lmc-base-classes
Commits
c055956e
Unverified
Commit
c055956e
authored
3 years ago
by
SKAJohanVenter
Browse files
Options
Downloads
Patches
Plain Diff
SAR-275
Added more docs
parent
8696a1b7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ska_tango_base/base/task_queue_component_manager.py
+76
-9
76 additions, 9 deletions
src/ska_tango_base/base/task_queue_component_manager.py
tests/test_task_queue_component_manager.py
+3
-3
3 additions, 3 deletions
tests/test_task_queue_component_manager.py
with
79 additions
and
12 deletions
src/ska_tango_base/base/task_queue_component_manager.py
+
76
−
9
View file @
c055956e
"""
This module provides a QueueManager
and
TaskResult classes.
This module provides a QueueManager
,
TaskResult
and QueueTask
classes.
* **TaskResult**: is a convenience `dataclass` for parsing and formatting the
results of a task.
...
...
@@ -36,9 +36,12 @@ be made available as a Tango device attribute named `command_result`. It will be
QueueTask
*********
This class should be subclass
s
ed and the `do` method implemented with the required functionality.
This class should be subclassed and the `do` method implemented with the required functionality.
The `do` method will be executed by the background worker in a thread.
`get_task_name` can be overridden if you want to change the name of the task as it would appear in
the `tasks_in_queue` property.
Simple example:
.. code-block:: py
...
...
@@ -93,6 +96,70 @@ Simple example:
time.sleep(0.5)
return ProgressTask()
************
QueueManager
************
The queue manager class manages the queue, workers and the update of properties.
The number of worker threads can be specified.
In the case of no worker threads, tasks that are enqueued will *not* be put on the queue,
but will simply be executed and thus block until done. No worker threads are started in this case.
As tasks are taken off the queue and completes, the properties below will be updated. An optional callback
`on_property_update_callback` can be specified that will be executed for every property change. This callback
will be called with the name of the property and its current value.
* **tasks_in_queue**: A list of names for the tasks in the queue.
Changes when a queue item is added or removed.
* **task_ids_in_queue**: A list of unique IDs for the tasks in the queue.
Changes when a queue item is added or removed.
* **task_result**: The result of the latest completed task. Changes when task completes.
* **task_status**: A list of unique IDs and the their status.
Currently indicates when a task is in progress and changes when a task is started or completed.
Other properties of note:
* **queue_full**: Indicates whether the queue is full or not.
If the queue is full, the result of any enqueued task will immediately be set to REJECTED.
* **task_progress**: When reading this property the progress of the tasks are fetched from the worker threads.
Aborting tasks
--------------
When `abort_tasks` is called on the queue manager the following will happen.
* Any tasks in progress will complete. Tasks that check `is_aborting_event` will know to complete otherwise
it will complete as per normal.
* Any tasks on the queue will be removed and their result set to ABORTED. They will not be executed.
* Any tasks enqueued while in aborted state will immediately be removed from the queue and marked as ABORTED.
* The thread stays alive.
When `resume_tasks` is then called, tasks are again put on the queue, retrieved and executed as per normal.
Stopping tasks
--------------
Once `stop_tasks` is called the worker threads completes as soon as possible.
* Any tasks in progress will complete. Tasks that check `is_stopping_event` will know to exit gracefully.
* The thread will cease.
Getting the state of a task
---------------------------
Calling `get_task_state` with the task ID will check the state of the task. A history of completed tasks
are not kept, so it may not be found.
"""
from
__future__
import
annotations
import
enum
...
...
@@ -361,7 +428,7 @@ class QueueManager:
):
"""
Init QueryManager.
Creates the queue and starts the thread that will execute
command
s
Creates the queue and starts the thread that will execute
task
s
from it.
:param logger: Python logger
...
...
@@ -533,17 +600,17 @@ class QueueManager:
property_name
,
getattr
(
self
,
property_name
)
)
def
abort_
command
s
(
self
):
"""
Start aborting
command
s.
"""
def
abort_
task
s
(
self
):
"""
Start aborting
task
s.
"""
for
worker
in
self
.
_threads
:
worker
.
is_aborting
.
set
()
def
resume_
command
s
(
self
):
"""
Unsets aborting so
command
s can be picked up again.
"""
def
resume_
task
s
(
self
):
"""
Unsets aborting so
task
s can be picked up again.
"""
for
worker
in
self
.
_threads
:
worker
.
is_aborting
.
clear
()
def
stop_
command
s
(
self
):
def
stop_
task
s
(
self
):
"""
Set is_stopping on each thread so it exists out. Killing the thread.
"""
self
.
is_stopping
.
set
()
...
...
@@ -595,7 +662,7 @@ class QueueManager:
if
not
self
.
_threads
:
return
self
.
abort_
command
s
()
self
.
abort_
task
s
()
self
.
_work_queue
.
join
()
for
worker
in
self
.
_threads
:
worker
.
is_stopping
.
set
()
...
...
This diff is collapsed.
Click to expand it.
tests/test_task_queue_component_manager.py
+
3
−
3
View file @
c055956e
...
...
@@ -398,7 +398,7 @@ class TestQueueManagerExit:
while
not
qm
.
task_status
:
pass
# Start aborting
cm
.
message_queue
.
abort_
command
s
()
cm
.
message_queue
.
abort_
task
s
()
# Wait for the exit
while
not
qm
.
task_result
:
pass
...
...
@@ -411,7 +411,7 @@ class TestQueueManagerExit:
break
# Resume the commands
qm
.
resume_
command
s
()
qm
.
resume_
task
s
()
assert
not
qm
.
is_aborting
# Wait for my slow command to finish
...
...
@@ -440,7 +440,7 @@ class TestQueueManagerExit:
while
not
qm
.
task_status
:
pass
# Stop all threads
cm
.
message_queue
.
stop_
command
s
()
cm
.
message_queue
.
stop_
task
s
()
# Wait for the exit
while
not
qm
.
task_result
:
pass
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment