Skip to content

Python Function Decorator

In addition to the taskbadger.Task class and utility functions, there is also a function decorator that can be used to automatically create a task when a function is called.

from taskbadger import track

@track("my task")
def my_function():
    pass

Using the decorator will create a task with the name provided and automatically update the task status to success when the function completes or error if an exception is raised.

The decorator also applies the taskbadger.Session context manager to the function. See connection management.

API Docs

taskbadger.track

track(func=None, *, name: str = None, monitor_id: str = None, max_runtime: int = None, **kwargs)

Decorator to track a function as a task.

Usage:

import taskbadger

@taskbadger.track
def test(arg):
    print(arg)

Parameters:

Name Type Description Default
name str

The name of the task. Defaults to the fully qualified name of the function.

None
monitor_id str

The ID of the monitor to associate the task with.

None
max_runtime int

The maximum runtime of the task in seconds. If the task takes longer than this, it will be marked as an error.

None
**kwargs {}