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.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

tasklist-1.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tasklist-1.2.0.tar.gz
  • Upload date:
  • Size: 6.4 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.3

File hashes

Hashes for tasklist-1.2.0.tar.gz
Algorithm Hash digest
SHA256 c90a7afd22015e0fe3be1873481c18d114793b9434e8c672fe164bae5931dbc3
MD5 f524a20f1e80e1d05938ce2138123a32
BLAKE2b-256 d686e7674b382dd0eba2950fda9491a3b6bdb2682cbf6bc2bc59e480af75d821

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tasklist-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 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.3

File hashes

Hashes for tasklist-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99785a4027e79ad4874ffc94855aafe2d21c8e47a619009de195cf073b71f179
MD5 201d4c6fb64e24b61818f003d94030de
BLAKE2b-256 2a6e964963964b9f30e9a4b5d3914734b8b75d8d25cbea641f254e0d38bdc1b3

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