Skip to main content

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':

>>> queue.process(preview=False)
[<cyberfusion.QueueSupport.outcomes.ChmodItemModeChangeOutcome object at 0x7f947e8ef510>]
>>> print(queue.process(preview=True)[0])
Change mode of /tmp/example.txt from 0o644 to 0o600

... then actually run the chmod:

>>> print(queue.process(preview=False)[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

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

outcomes = queue.process(preview=preview)

for outcome in outcomes:
    print(str(outcome))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python3_cyberfusion_queue_support-1.6.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file python3_cyberfusion_queue_support-1.6.tar.gz.

File metadata

File hashes

Hashes for python3_cyberfusion_queue_support-1.6.tar.gz
Algorithm Hash digest
SHA256 ed37636f0ecce1f5daae76a6b9d7ba0cf37751fa6f70f1e571a2c89c989c1708
MD5 b934d125e1c7ff0091ddc547ef1b62aa
BLAKE2b-256 884dbdddc3bf31b2f15019c5223b6606cfad059466db5636415e8df5d11e7e3d

See more details on using hashes here.

File details

Details for the file python3_cyberfusion_queue_support-1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for python3_cyberfusion_queue_support-1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 41f0eb08d97b91a65b74f8d0225d1714c0e84a3c19ff7e2bb2327d6c05cc09f5
MD5 b70cb6c3f59092df2c9d5c83b4e927c4
BLAKE2b-256 64dbd7802816df58b064e92cb4beaf2b43f460295d63f88c7a5eed04ef776207

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page