-
-
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
- Import workflow and Tasks object from workflow module in taskcontrol package
- Create a Task instance
- Create a workflow definition using
@workflow
decorator- Usage:
@workflow(name, task_order, task_instance, args, kwargs, before, after, shared, log)
def function(...){...}
-
name
,task_instance
keys definitions are compulsary -
args
,kwargs
, optional for function arguments - throwsTypeError
if wrong args provided -
before
andafter
keys are optional and provides before and after middlewares for a specific task -
shared
key is optional and defaults toFalse
-
log
key 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()