Task#
A task is a function that represents a discrete unit of work in a workflow. Tasks enable you to encapsulate elements of your workflow logic in observable units that can be used individually and be reused within flows.
Tasks are functions: They can take inputs, perform work and return an output. A perfect task can do almost anything a Python function can do. Use the @task decorator to designate a function as a task. All tasks can be executed seperately or be called within a task and can be called from within a flow.
Let’s look at how a task can be created in Jupyter Notebook and the various task functions.
To watch the video, click on Subscribing to Tasks and Flows.
Create#
To start the process of creating a task, users need to import the task module from the conversight library. A task should comprise a name, tags, functions, a task description (or docstring) and a try and except block. The task’s name is an optional parameter; if left empty, the function name will be used instead.
To watch the video, click on Creating a Task.
Sample Code
from conversight import task, Context
@task(name="multiplication", tags=["Arithmetic", "calculation"])
def multiply(ctx : Context, x: int, y: int) -> int:
"""A simple multiplication function""" #task description or docstring
try:
ctx.log.info("Multiplication Started")
return x * y
except Exception as err:
ctx.log.error(f"Exception in newTask ==> {err}")
return err
In the function provided above, both the docstring and code are enclosed within a try/except block. This practice is standard on the ConverSight platform for task registration. Without it, further task actions like running or registering cannot be performed.
Now that the function has been created, we can execute it or verify its functionality using the run() method.
NOTE
The print statement is restricted in Tasks and Flows.
Run#
To execute a task, utilize the run() function and input the required parameters in the specified format.
Syntax: Taskname.run(Argument1, Argument2)
multiply.run(7,7)
#this will execute the task "multiply" and the Output will be '49'

Run a task#
Register#
To register a task, you must provide input arguments such as the library name, description, source control, API access, deployable, task type and debug. Shift + Tab displays information about the input arguments required to register a task.
Argument |
Description |
---|---|
Library Name |
Providing the library name is essential for task registration. It can be an existing name or a new one; if it is new, a new library will be created. Libraries serve as logical groupings of tasks and it is important to note that empty spaces are not permitted in the Library Name. |
Description |
Textual explanation that provides context, details or information about the task. |
Source Control |
The task created has access controls such as view, edit and noAccess. The default is set to noAccess. |
API Access |
This is a boolean parameter. The default is set to false. When we set it to true, the task will be executed through the API resource. |
Deployable |
Deployable is almost the same as API Access. The task will always be in memory, running at the back end and will give an instant output when input is provided. This is also a boolean parameter. The default is set to False. |
Task Type |
There are two task types. They are generic tasks and UI tasks, any task we create using @task is generic. UI task is created with @uitask, which will work only on the user interface. The default is set to generic task. |

Register a task#
Syntax: TaskName.register(libraryName, description, sourceControl, apiAccess, deployable, athenaAccess, taskType, debug)
multiply.register(libraryName="Arithmetic", description="Calculation", sourceControl="edit",apiAccess=False, deployable=False, athenaAccess=False, taskType="generic",debug=False)
#now task "multiply" has been successfully registered. The most recent version available is 0.1.

Register a task#
Promote#
Through task promotion, users can adjust the visibility level of a task, with options such as user, platform and organization.
Platform Level: Promoting a task to the platform level makes it accessible to all platform users.
Organization Level: Promotion to organization level makes the task available to users within that specific organization.
User Level: Task promotion at the user level ensures availability exclusively to that particular user.
As a default setting, tasks created from notebooks are categorized under the U level (user). To access the task at the organizational level, users should switch the level to O (Org) using the promote() method. For platform-level access, the level needs to be changed to P.
Shift + Tab shows the details about the input arguments required to promote a task.
Arguments |
Description |
---|---|
Library Name |
Provide the library name which is mandatory to promote a task. |
Level |
Input the level to be promoted such as U, O and P. |
Version |
Specify the version of the task to be promoted. This is an optional parameter. If no version is specified, the latest version of the task will be promoted by default. |

Promote a task#
Syntax: TaskName.promote(libraryName, level, version, debug)
multiply.promote(libraryName="Arithmetic", level="O", version=0.1, debug=False)
#this will promote the task "demotask" to "O".

Promote a task#
Additional Functions#
Now that a task has been created, registered and promoted, it is stored for future use in the TaskLibrary. The TaskLibrary serves as a catalog within ConverSight, containing all available tasks categorized by their respective libraries.
Next, we will import the TaskLibrary from ConverSight to leverage a variety of task management functionalities.
Syntax:
from conversight import TaskLibrary
tsk = TaskLibrary()

Importing TaskLibrary#
Utilizing the reload() function allows users to update the TaskLibrary and access the most recent version of the task efficiently.
Syntax: tsk.reload()
The TaskLibrary will now contain the newly created task multiply.
When you click the Tab, a list of task library names will appear.
After selecting the library name, pressing the Tab key again will display a list of tasks available under the specified task library.
After selecting the task name, pressing the Tab key will display a list of the available functions.
The additional functions available are:
Show Code
Edit Code
Get Versions
Set Version
Delete Version
Delete

Additional Functions#
Show Code#
Function showCode is used to display the task’s code. By default, it displays the code of latest version.
Syntax: tsk.LibraryName.TaskName.showCode()
tsk.Arithmetic.multiplication.showCode()
#this will show the code of latest version.

Show Code Function#
Edit Code#
Function editCode is used to modify an existing task’s code. It displays the code of the latest version by default. When the code is edited and registered, a new version of that task is created.
Syntax: tsk.LibraryName.TaskName.editCode()
tsk.Arithmetic.multiplication.editCode()
#this will show the code of latest version in edit mode, any changes made to this will be saved and registered as a new version.

Edit Code Function#
Get Versions#
The getVersions function returns a list of all available versions for a task.
Syntax: tsk.LibraryName.TaskName.getVersions()
tsk.Arithmetic.multiplication.getVersions()
#this will provide the list of versions available for the task "demotask"

Get Versions Function#
Set Version#
This function is utilized to designate a task’s version as per the user’s specification. After setting the version, you can make edits and modifications to that particular version of the task. Upon modification, users can execute additional functions such as promoting, obtaining the version, displaying code, editing code and deleting the version for the altered task version.
Syntax: tsk.LibraryName.TaskName.setVersion(version_number)
tsk.Arithmetic.multiplication.setVersion(0.1)
#this will set the version to 0.1

Set Version Function#
Delete Version#
The deleteVersion function allows users to delete a particular version of the task.
Syntax: tsk.LibraryName.TaskName.deleteVersion(version_number)
tsk.Arithmetic.multiplication.deleteVersion(0.2)
#this will delete the version 0.2

Delete a version of a task#
Delete#
With this function, the task and all of its versions are permanently deleted. It will request for confirmation of the task name before deleting the task. The task will be deleted after we provide its name and click delete.
Syntax: tsk.LibraryName.TaskName.delete()
tsk.Arithmetic.multiplication.delete()
#this will delete the task "multiplication"

Delete Function#
Once the task name is entered and the delete option is chosen, the task and all of its versions are permanently deleted.

Delete a task#
Utilizing Chained Tasks#
Chained Tasks in ConverSight refers to a series of tasks where the output of a task or a task’s function becomes the input for the next task in a sequential manner. This composition of tasks creates a chain or pipeline, allowing the reuse of functions or tasks, efficient code design, an organized way to process data and perform complex operations. To use the chain tasks or output of one task which acts as the input for another, follow these steps:
Create two separate tasks, as explained earlier.

Create Main Task#
Once created register both tasks using the register() command.

Create and Register Chained Tasks#
Pass the output of the first task as the input parameter for the second task as shown below to get the final result.
@task
def newtask(ctx : Context, x: int, y: int) -> int:
"""A simple multiplication function""" #task description or docstring
try:
ctx.log.info("Output Received")
return tsk.Arithmetic.finaltask.run(x * y)
except Exception as err:
ctx.log.error(f"Exception in newTask ==> {err}")
return err
Execute the task that yields the required final outcome using the run() command.

Chained Tasks Output#