Skip to main content

taskcontrol

Create named shared / isolated workflow task controls, and run them with respective before/after middlewares

taskcontrol is a python library to create tasks in and based on named workflow controls. It allows middlewares before and after each task. taskcontrol can run single or multiple tasks at a task run invocation.

It provides a simple decorator called workflow that takes the name, task_instance, task_order, shared, before, after arguments to set up the named workflow controls.

It also provides methods to create a plugin and work with tasks as a module and/or pre-created ordered task list.

Features

  • Create Named task controls (tasks) - instance and isolated
  • Allows middlewares before / after each task (data fetch, auth, data save, logging, logout, cleanup, etc)
  • Access read-only contexts and results of middlewares/tasks
  • Allows Merging two instances of task controls with namespace clash handling
  • Run instance, shared, and mix of tasks (individual or all groups)
  • In-Development: Allows creating, registering, and using task controls as a plugin

Installation

Command:
  • Python

      pip3 install taskcontrol
    
Version:
In Development Version: 1.2.0 (functional - production ready with plugin and concurrency support)
Current Version: 1.2.0 (functional - production ready with most planned features with MVP)
Previous Version: 1.1.0 (functional - not production ready)
Package Link:
https://github.com/taskcontrols/py-taskcontrol
https://pypi.org/project/taskcontrol/

Technical Specifications

Requirements:
  • Python 3.x
  • Any OS supporting Python 3.x
Package Dependencies:
  • None
Quick Demo:

demo example - main.py

from taskcontrol import workflow, Tasks

inst = Tasks()

def middleware(ctx, result, k, c, d, **kwargs):
    print("Running my Middleware Function: test - task items", k, c, d, kwargs)


@workflow(
    name="taskname",
    task_order=1,
    task_instance=inst,
    shared=False,
    args=[1, 2],
    kwargs={},
    before=[
        {
            "function": middleware,
            "args": [11, 12],
            "kwargs": {"d": "Before Testing message Middleware "},
            "options": {"error": "next", "error_next_value": ""}
        }
    ],
    after=[
        {
            "function": test,
            "args": [13, 14],
            "kwargs": {"d": "After Middleware Testing message"},
            "options": {
                "error": "error_handler",
                "error_next_value": "value",
                "error_handler": lambda err, value: (err, None)
            }
        }
    ],
    log=False
)
def taskone(ctx, result, a, b):
    print("Running my task function: taskone", a, b)


# Run single task
t.run(tasks="taskname")


# Run all tasks
t.run(tasks=["1"])
# t.run(tasks=["taskname", ..., "anothertask"])
Note:

Though it may support Python version 2.x. However, it has not been tested in 2.x. The Syntax and Features of the library supports Python version 2.x. Use at your own risk.

Wiki

Crazy Hint:

You can also create a simple workflow without taskcontrol using a simple list or nested list and loop through them using a for/while loop and invoke them during looping

# Loop the lists below and invoke the functions 
lst = ["f1", "f2", "f3"]
nest_lst = [["f1", "f2"], "f3", "f4", ["f5"]]


# Use a reducer if you want to send args to next function like below
def test(a,b):
    print(a,b)
    return {"a":a, "b":b}
def tester(a,b):
    print(a,b)
    return None

kwargs_for_first_function_the_its_returns_or_other_value_for_next_func = {"a":"a", "b":"b"}
ls = [kwargs_for_first_function_the_its_returns_or_other_value_for_next_func, test, tester]
import functools 
def red(kwargs_for_first_then_func, p):
    i = p(kwargs.get("a"), kwargs.get("b"))
    return i
functools.reduce(red, ls)

Todo

  • e2e and Unit Tests - Add Tests (Structure of package created - to be cleaned after writing tests)
  • Allow creating and registering a set of task controls as a plugin
  • Add logging system

Status

  • In Active Development (taskcontrol version 1.2.1)

Support

Paypal.me/taskcontrols

OpenCollective

License

The MIT License (MIT) - See LICENSE for further details

Copyright © 2020 - till library works

taskcontrols@gmail.com

Release files for taskcontrol 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for taskcontrol 1.1.2
File Size Uploaded
taskcontrol-1.1.2.tar.gz 145.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for taskcontrol 1.1.2
File Interpreter ABI Platform
taskcontrol-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 154.3 kB

Release files / taskcontrol-1.1.2.tar.gz

Download URL taskcontrol-1.1.2.tar.gz
Size 145.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d504073bf1555d46dbb9fc5222b3d80d227c6abb9579899ba8f2b53b3e11789a
BLAKE2b-256 checksum
How to use checksums
d188e1ded18d43e981d12803da1facbf3568ec5815436529aed7745ac1405b28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release files / taskcontrol-1.1.2-py3-none-any.whl

Download URL taskcontrol-1.1.2-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1132fbb63f4414c540573812eb8fe2903efabc3d15deea7041d139eeccb6360
BLAKE2b-256 checksum
How to use checksums
e9d16de02bca423a6ba19d3c4289f7593de6581e10cadd73808a0954c18756e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page