-
-
Notifications
You must be signed in to change notification settings - Fork 2
Getting Started with Taskcontrol
Ganesh Bhat edited this page Nov 18, 2021
·
5 revisions
Create named shared / isolated workflow task controls, and run them with respective before/after middlewares. taskcontrols also supports plugins, concurrency, and authentication
- Import workflow and Tasks object from workflow module in taskcontrol package
- Create a Task instance
- Create a workflow definition using
@workflowdecorator- Usage:
@workflow(name, task_order, task_instance, args, kwargs, before, after, shared, log)def function(...){...}
-
name,task_instancekeys definitions are compulsary -
args,kwargs, optional for function arguments - throwsTypeErrorif wrong args provided -
beforeandafterkeys are optional and provides before and after middlewares for a specific task -
sharedkey is optional and defaults toFalse -
logkey is optional and default toFalse
- Usage:
- Run the task when needed using
.run(tasks=['taskname'])invocation
# for package
from taskcontrol import workflow, Tasks
# Create an instance of the task you are creating
sparrow = Tasks()
# Middleware that we are running
# Use any middleware that runs with or withour returning results
# Demo uses common middleware for all. Please use you own middlewares
def nesttree(ctx, result, *args, **kwargs):
print("Running my Middleware Function: nesttree - task items", args, kwargs)
# workflow decorator
@workflow(
# Task name
name="taskname",
# Task instance which is used for creating tasks
# Tasks are isolated to this task instance
task_instance=sparrow,
# Arguments that should be provided to the task function the decorator is applied on
args=[1, 2],
# Keyword arguments for the function the decorator is applied on
kwargs={},
)
# Main function for the task
def taskone(ctx, result, *args, **kwargs):
print("Running my task function: taskone", args, kwargs)
sparrow.run()