The Badgers Print 🐾 Nov 2023

The last few months have been a real whirlwind while I've been getting Task Badger ready for a wider release. I'm excited to share that we are now being featured on DevHunt so go check it out and give us an upvote!

I've made a lot of improvements to the product that I'm really excited about. Let's take a look.

Global actions

Global actions

From the beginning it has been possible to add 'actions' to tasks which allows you to run an integration based on the action's trigger. For example, you can add an action to send an Email message when a task is completed, or possibly more importantly, if the task doesn't complete.

Now with global actions you can add actions that will run for all tasks. You can also limit it to tasks in a specific project or tasks whose name matches a pattern. This is a great way to add a global integration to all your tasks.

Celery Integration

This is the one I really want to talk about because it's so cool. We've added an integration with Celery which is a distributed task queue. It's the most commonly used task queue for Python projects. Most of the projects I've worked on use Celery.

When we first released our Python SDK you could use it to monitor Celery tasks, but it was very a manual process and a bit messy. Now we've added a Celery integration which will automatically monitor all your Celery tasks.

We also provide a Celery task class which gives you easy access to the Task Badger Task object from within your Celery task. This allows you to easily update the task status.

Let's have a look at some examples.

Monitoring all Celery tasks

In cases where you want to monitor all you Celery tasks but don't necessarily need access to the task object within the task itself, you can use the CelerySystemIntegration class.

This provides a much easier way to monitor your tasks without having to add any code to the task declaration. Having all your tasks monitored is a great way to get a global view of what's happening in your backend system. In the future we'll be adding features to make this even more useful like aggregate metrics.

Here's how you configure this and notice that you can include or exclude tasks based on the task name.

import taskbadger
from taskbadger.systems import CelerySystemIntegration

taskbadger.init(
    organization_slug="my-org",
    project_slug="my-project",
    token="***",
    systems=[CelerySystemIntegration(
        includes=[
            "myapp.tasks.*",
            "myapp.other_tasks.special_task"
        ],
        excludes=[
            "myapp.tasks.heartbeat",
        ]
    )]
)

Monitoring a single Celery task

If you only want to monitor a few tasks or if you want to have access to the Task Badger Task object within the task body, we provide a base class which you can use when defining your Celery tasks.

from celery import Celery
from taskbadger.celery import Task

app = Celery("tasks")

@app.task(bind=True, base=Task)
def my_task(self, items):
    task = self.taskbadger_task

    for i, item in enumerate(items):
        do_something(item)

        if i % 100 == 0:
            # Track progress
            task.update(value=i)

    task.success(value=len(items))


result = my_task.delay(items, taskbadger_value_max=len(items))
taskbadger_task_id = result.taskbadger_task_id
taskbadger_task = result.get_taskbadger_task()

You can pass additional keyword arguments in the task decorator or to the delay method which will be used when creating the Task Badger Task. In this case we're setting the value_max property so that we can get an accurate progress bar.

This can easily be used in conjunction with the CelerySystemIntegration approach above.

To find out more about the Celery integration, check out the documentation.

Task List Improvements

Task List

The main task list has had a number of improvements made to it. The table now has a graph at the top showing the number of tasks completed. We've also added search and filtering options and a display of task duration.

Scheduled Task Monitoring

Sheduled Task Monitors

We've officially launched schedule task monitoring, bringing it out of beta. Additionally, we've updated the CLI to support this feature. Personally, I've found it useful for keeping an eye on my laptop's virus scans and backups. What's more, we've introduced a Webhook integration that can be triggered by task actions.

What's next?

Stay tuned for more updates. I'm working on a number of new features including a Slack integration, a new dashboard, and more.

Subscribe for Updates

Sign up to get notified when we publish new articles.

We don't spam and you can unsubscribe anytime.