Library to queue actions.
Project description
python3-cyberfusion-queue-support
Library to queue actions.
QueueSupport allows you to queue certain actions, such as restarting a service, unlinking a file, and much more.
For example, suppose the file /tmp/example.txt should be chmodded to 0600. You can queue the chmod:
>>> from cyberfusion.QueueSupport import Queue
>>> from cyberfusion.QueueSupport.items.chmod import ChmodItem
>>> queue = Queue()
>>> queue.add(ChmodItem(path="/tmp/example.txt", mode=0o600))
... see what the chmod would do with 'preview mode':
>>> process, outcomes = queue.process(preview=False)
>>> outcomes
[<cyberfusion.QueueSupport.outcomes.ChmodItemModeChangeOutcome object at 0x7f947e8ef510>]
>>> process, outcomes = queue.process(preview=True)
>>> print(outcomes[0])
Change mode of /tmp/example.txt from 0o644 to 0o600
... then actually run the chmod:
>>> process, outcomes = queue.process(preview=False)
>>> print(outcomes[0])
Change mode of /tmp/example2.txt from 0o644 to 0o600
Install
PyPI
Run the following command to install the package from PyPI:
pip3 install python3-cyberfusion-queue-support
Then, run database migrations:
bin/queue-support-migrate
Debian
Run the following commands to build a Debian package:
mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
dpkg-buildpackage -us -uc
Configure
No configuration is supported.
Usage
Concepts
All project-specific terms are in italic.
After creating a queue, items can be added to it.
from cyberfusion.QueueSupport import Queue
queue = Queue()
item = ...
queue.add(item)
Items are of a certain type. Such as ChmodItem or SystemdUnitRestartItem. Items can have attributes, such as a path for an MkdirItem, or a unit name for SystemdUnitEnableItem.
from cyberfusion.QueueSupport.items.chmod import ChmodItem
from cyberfusion.QueueSupport.items.systemd_unit_enable import SystemdUnitEnableItem
item1 = ChmodItem(path="/tmp/example.txt", mode=0o600)
item2 = SystemdUnitEnableItem(name="httpd.service")
Each item type has one or multiple outcomes. These should come true for an item of that type to be completed. For example: for an item of type UnlinkItem, the outcome is that the file at the path given with the item is unlinked.
When a queue is processed, all the items added to it are fulfilled, meaning all the items' outcomes come true.
from cyberfusion.QueueSupport import Queue
from cyberfusion.QueueSupport.items.rmtree import RmTreeItem
item = RmTreeItem(path="/tmp/dir")
queue = Queue()
queue.add(item)
# Fulfill every item in the queue
queue.process(preview=False)
queue.process(preview=True) # Only show what the outcomes would be
# Fulfill a single item
item.fulfill()
Diagram
graph TD;
subgraph QueueSupport
Queue["Queue"]
Item["Add item"]
Process["Process (fulfill all items)"]
end
Queue --> Item
subgraph ItemTypes["Item types"]
ChmodItem["ChmodItem"]
SystemdUnitEnableItem["SystemdUnitEnableItem"]
SystemdUnitRestartItem["SystemdUnitRestartItem"]
MkdirItem["MkdirItem"]
UnlinkItem["UnlinkItem"]
RmTreeItem["RmTreeItem"]
Other["Others..."]
end
Item --> ItemTypes
ItemTypes --> Outcome["Outcome (item's goal)"]
Process --> Fulfill["Fulfill outcomes for each item"]
%% Example flows for item attributes and outcomes
ChmodItem -.->|path, mode| Outcome
SystemdUnitEnableItem -.->|unit name| Outcome
MkdirItem -.->|path| Outcome
UnlinkItem -.->|unlink file| Outcome
RmTreeItem -.->|remove directory| Outcome
Queue --> Process
Process --> Fulfill
Example
from cyberfusion.QueueSupport import Queue
from cyberfusion.QueueSupport.items.chmod import ChmodItem
queue = Queue()
item = ChmodItem(path="/tmp/example.txt", mode=0o600)
print(item.outcomes)
queue.add(item)
preview = True or False
process, outcomes = queue.process(preview=preview)
print(process.status)
for outcome in outcomes:
print(str(outcome))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python3_cyberfusion_queue_support-3.0.2.tar.gz.
File metadata
- Download URL: python3_cyberfusion_queue_support-3.0.2.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cce31d6e702d436657d78500aa69833e180d3482093fc31438732b6c4c89b50
|
|
| MD5 |
28e98fa2b1bc79521a4400f12f18ac5e
|
|
| BLAKE2b-256 |
17ef215c9e1ac85bfd7abe4d1389382efd690c580ab043086f1526fee8037d44
|
File details
Details for the file python3_cyberfusion_queue_support-3.0.2-py3-none-any.whl.
File metadata
- Download URL: python3_cyberfusion_queue_support-3.0.2-py3-none-any.whl
- Upload date:
- Size: 36.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d91faa9920b5cb01985cd46b83d00ac365116a9fee2e7baf011e672e0bd0df21
|
|
| MD5 |
f3cafdc3f52a9eff3a34481e62d022cf
|
|
| BLAKE2b-256 |
195882e3e9a94ddaa779589fcb6faed8615d69efac1687ca9280035f27305321
|