Skip to main content

A library to manage lists of commands with re-trial.

Project description

Overview

coverage

A simple way to ensure that a list of commands is executed successfully, or re-tried.

Tasklist allows to the following:

  • Execute lists of commands (tasks)
  • Verify their success
  • Re-execute commands that failed, order-preserving
  • Control temporary and permanent command statuses
  • Discard tasks with temporary failures after a tryout
  • Discard tasks with temporary failures after a timeout
  • Persist the list of tasks so it's reloaded when your program fails

Main applications

  • DevOps pipelines which require multiple commands to reach a desired state
  • Servers which accept operations which may fail and are required to retry them
  • Event Sourcing architectures where events are executed with commands
  • Manual processes which may be interrupted for a failure, and need to be resumed from there

Examples

Ensure complete termination of interrupted process

from tasklist import TaskList, Task

# make sure all of the following commands are executed
commands = [
    "tar cjvf maillog.tbz /var/log/maillog",
    "rm -f /var/log/maillog",
    "service myservice restart"
]

# create a tasklist
tl = TaskList()
for cmd in commands:
    tl.add(Task(cmd=cmd.split()))

if tl.run_all():
    # some task failed. Sleep a while and retry
    tl.run_all()

Manage temporary and permanent failures

import time
from tasklist import TaskList, Task

t = Task(cmd="false")
t.run()                     # False (executed with failure)
t.failed_retry()            # False (failed with non-retriable exit status)
time.sleep(10)
t.age()                     # 10 (created 10 seconds ago)

t = Task(cmd="python", args=["-c", "import sys; sys.exit(2)"])
t.run_all()                 # False
t.failed_retry()            # True (failed with retriable exit status)

Making the queue persistent

from tasklist import TaskList, Task

# automatically persist the tasklist at the given path in the filesystem
tl = TaskList(wrkdir='/tmp/mytasklist', autosync=True)
tl.add(Task(cmd="true"))
tl.add(Task(cmd="false"))
del tl

new_tl = TaskList(wrkdir='/tmp/mytasklist', autosync=True)
len(new_tl)                     # 2 tasks

Support

This is open-source software contributed by the BuddyNS team. The project is hosted at https://gitlab.com/BuddyNS/tasklist.

Please do not contact BuddyNS for support with this library. You can get general support on Python from the great people of the #python channel on the freenode IRC network.

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

tasklist-1.2.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

tasklist-1.2.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file tasklist-1.2.1.tar.gz.

File metadata

  • Download URL: tasklist-1.2.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for tasklist-1.2.1.tar.gz
Algorithm Hash digest
SHA256 bc2e2bd89c98916021c76a477d056cfe22d79128d7cd976e7271303fc4e3c9a7
MD5 b50369ef76e4ff6378b1b042cfc40fb3
BLAKE2b-256 10ebd0657633f3c81ebb1f344c647dafca3853766363775ab7fdad8d6cbf115a

See more details on using hashes here.

File details

Details for the file tasklist-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: tasklist-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for tasklist-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 812e44ca5e056812e987c353b9a7695fdfaf5317ff5ea3f40b03d3b1408045cd
MD5 2fe60b5fb6a9050a6e7463ee46235fb0
BLAKE2b-256 3e28fd9de6f3aa2ff7196d29bbdd8f3ad5746de54ac4c73f4305b037c8f0055c

See more details on using hashes here.

Supported by

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