Skip to content

Getting Started with Taskcontrol

Ganesh Bhat edited this page Nov 18, 2021 · 5 revisions

Usage

  • 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 - throws TypeError if wrong args provided
    • before and after keys are optional and provides before and after middlewares for a specific task
    • shared key is optional and defaults to False
    • log key is optional and default to False
  • Run the task when needed using .run(tasks=['taskname']) invocation

Simple Usage Demo Code

# 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()
Clone this wiki locally