Skip to content

Conversation

@Chiemezuo
Copy link
Member

Description

This PR creates a panel for Django Tasks to allow the Debug Toolbar to monitor queued tasks.

Fixes #2204

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.



@task
def send_welcome_message(message):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest setting up some tasks that follow the Django examples tasks closely:

https://docs.djangoproject.com/en/dev/topics/tasks/

That will help it feel a bit more 'real-world' and may inspire further ideas for functionality in the panel itself :-)

return render(request, "index.jinja", {"foo": "bar"}, using="jinja2")


async def async_home(request):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with this codebase, but when does this view get used?

I'd defer to @tim-schilling and others, but it may make sense to have a dedicated view for triggering off example tasks vs, say, triggering every time you visit an example home page. That could also be a bit more self-documenting and give a place to build off of for the future (like testing larger queues, reporting results on a page template, etc)

<table>
<thead>
<tr>
<th>Task Info</th>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be wrapped for translation :-)

try:
from django.tasks import task
except ImportError:
# Define a fallback decorator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the cases where this could happen? I'm guessing just in older django versions?

Is a fallback decorator a common pattern in this case? I think if its an example meant to work with tasks it shouldn't need a fallback, but I'd be interested to hear more of your thought process. :-)

"debug_toolbar.panels.cache.CachePanel",
"debug_toolbar.panels.signals.SignalsPanel",
"debug_toolbar.panels.community.CommunityPanel",
"debug_toolbar.panels.tasks.TasksPanel",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tim-schilling I wonder if it would make sense to check for the Django version here, and only include it if its on a Django version that supports the tasks?

Copy link
Contributor

@robhudson robhudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress!

return False
return True
except (ImportError, AttributeError):
return False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to be used in the enable_instrumentation method? Seems like it would fit there. The import django can go at the top with the other imports and you can remove the exceptions for that. This project has django as a dependency so it's safe to assume Django is available.

self._record_task(task, args, kwargs, result)
return result

Task.enqueue = wrapped_enqueue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task wrapping looks great. That seems to be the main bits needed to collect stats for the toolbar panel. Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Tasks panel

3 participants