forked from slides/empowering-django-with-background-workers
First pass of updates for Django London
This commit is contained in:
parent
33f4e655ca
commit
ffd2ce1f50
1 changed files with 27 additions and 59 deletions
86
slides.md
86
slides.md
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
title: Empowering Django with Background Workers
|
||||
title: Bringing Background Workers to Django
|
||||
class: text-center
|
||||
highlighter: shiki
|
||||
transition: slide-left
|
||||
|
@ -9,11 +9,12 @@ themeConfig:
|
|||
primary: '#0c4b33'
|
||||
---
|
||||
|
||||
# Empowering <logos-django class="[&>path]:fill-white! h-15 w-43"/> with Background Workers
|
||||
# Bringing Background Workers to <logos-django class="[&>path]:fill-white! h-15 w-43"/>
|
||||
|
||||
## Jake Howard{.mt-5}
|
||||
|
||||
### Djangocon Europe 2024{.mt-5}
|
||||
### Django London{.mt-5}
|
||||
#### September 2024
|
||||
|
||||
<!--
|
||||
- Here to talk about Background Workers
|
||||
|
@ -30,6 +31,7 @@ layout: full
|
|||
<ul class="list-none! [&>li]:m-0! text-2xl mt-10">
|
||||
<li><mdi-fire class="fill-white"/> Senior Systems Engineer @ Torchbox</li>
|
||||
<li><logos-wagtail class="fill-white"/> Core, Security & Performance teams @ Wagtail</li>
|
||||
<li><logos-django-icon class="[&>rect]:hidden!" /> Django Software Foundation Member</li>
|
||||
<li><mdi-server-plus class="fill-white" /> I'm an avid self-hoster</li>
|
||||
<li><mdi-robot-excited class="fill-white" /> I help students build robots in my "spare" time <small>(https://srobo.org)</small></li>
|
||||
</ul>
|
||||
|
@ -49,8 +51,9 @@ layout: full
|
|||
- Hi
|
||||
- I'm Jake
|
||||
- Senior Systems Engineer at Torchbox
|
||||
- I'm also on the security team, and as of last week the core team for Wagtail
|
||||
- I'm also on the security team, core team and performance teams for Wagtail
|
||||
- Leading Django-based CMS
|
||||
- Since doing this talk at Djangocon, I'm also a DSF member
|
||||
- I exist in many places on the internet
|
||||
-->
|
||||
|
||||
|
@ -332,7 +335,7 @@ layout: section
|
|||
|
||||
<!--
|
||||
- Back to Django
|
||||
- This is Djangocon after all
|
||||
- This is Django London after all
|
||||
- In Python and Django, there are lots of different frameworks to achieve background workers
|
||||
-->
|
||||
|
||||
|
@ -609,6 +612,7 @@ layout: fact
|
|||
|
||||
<!--
|
||||
- In progress API spec for first-party background workers in Django
|
||||
- An approved Enhancement Proposal, slowly making its way into Django itself
|
||||
-->
|
||||
|
||||
---
|
||||
|
@ -678,7 +682,9 @@ from wagtail.models import Page
|
|||
from django.tasks import task
|
||||
|
||||
@task()
|
||||
def send_email_to_user(page: Page, user: User):
|
||||
def send_email_to_user(page_id: int, user_id: int):
|
||||
page = Page.objects.get(id=page_id)
|
||||
user = User.objects.get(id=user_id)
|
||||
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
||||
send_mail(
|
||||
subject=f"A change to {page.title} has been published",
|
||||
|
@ -688,7 +694,7 @@ def send_email_to_user(page: Page, user: User):
|
|||
)
|
||||
|
||||
for user in page.subscribers.iterator():
|
||||
send_email_to_user.enqueue(user)
|
||||
send_email_to_user.enqueue(user.id)
|
||||
```
|
||||
````
|
||||
|
||||
|
@ -714,48 +720,6 @@ for user in page.subscribers.iterator():
|
|||
- With 0 lines changed
|
||||
-->
|
||||
|
||||
---
|
||||
layout: center
|
||||
---
|
||||
|
||||
<v-click>
|
||||
|
||||
```python
|
||||
# settings.py
|
||||
EMAIL_BACKEND = "django.core.mail.backends.tasks.SMTPEmailBackend"
|
||||
```
|
||||
|
||||
</v-click>
|
||||
|
||||
<br />
|
||||
|
||||
```python
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.mail import send_mail
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from wagtail.models import Page
|
||||
|
||||
for user in page.subscribers.iterator():
|
||||
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
||||
send_mail(
|
||||
subject=f"A change to {page.title} has been published",
|
||||
message=email_content
|
||||
from_email=None, # Use the default sender email
|
||||
recipient_list=[user.email]
|
||||
)
|
||||
```
|
||||
|
||||
<!--
|
||||
- In this case, we can actually make it even easier
|
||||
- Because email is such a common use case, and so easy to extract
|
||||
- Let's go back to the simple implementation
|
||||
- No background workers in sight
|
||||
- [click]Instead, we can change the email backend
|
||||
- Emails are magically sent in the background automatically
|
||||
- Without additional work
|
||||
-->
|
||||
|
||||
---
|
||||
layout: image-right
|
||||
image: /soon.png
|
||||
|
@ -891,7 +855,7 @@ layout: section
|
|||
# Where are we now?
|
||||
|
||||
<!--
|
||||
- I mean, other than Vigo
|
||||
- I mean, other than Kraken HQ
|
||||
-->
|
||||
|
||||
---
|
||||
|
@ -916,19 +880,17 @@ layout: section
|
|||
</div>
|
||||
|
||||
<!--
|
||||
- You can play with this right now!
|
||||
- Download it, play around with it
|
||||
- The dummy backend is great for testing
|
||||
- The immediate backend can help get you started
|
||||
- The ORM backend is where the magic happens
|
||||
- Tell me about all the bugs in my code
|
||||
- The more testing we can do now, the better
|
||||
- You can use it right now
|
||||
- Please do, it's great!
|
||||
- For some projects, you won't need anything else
|
||||
- Report back the bugs
|
||||
- The more testing done now, the better
|
||||
- There's still work to do
|
||||
- Features
|
||||
- Improvements
|
||||
- Performance
|
||||
- Scalability
|
||||
- etc etc
|
||||
- The list goes on...
|
||||
-->
|
||||
|
||||
---
|
||||
|
@ -939,6 +901,8 @@ layout: section
|
|||
|
||||
<!--
|
||||
- More testing
|
||||
- More features
|
||||
- Writing task queues takes time
|
||||
- Upstreaming
|
||||
- That's the big benefit
|
||||
- Else it really is just another standard
|
||||
|
@ -948,6 +912,8 @@ layout: section
|
|||
- The more people know about this, the better it is for everyone
|
||||
- Developers can start working on integrating now
|
||||
- Knowing they can trivially upgrade once it's in Django
|
||||
- Integration
|
||||
- Can't use other libraries until the integrations exists
|
||||
-->
|
||||
|
||||
---
|
||||
|
@ -1003,6 +969,8 @@ class: flex justify-center flex-col text-xl
|
|||
- Bringing the stability and longevity guarantees that come with Django
|
||||
- Doesn't mean they'll never come
|
||||
- With your help, we can make these happen
|
||||
- Except swappable argument serialization
|
||||
- `pickle` is a bad idea
|
||||
-->
|
||||
|
||||
---
|
||||
|
@ -1047,7 +1015,7 @@ layout: section
|
|||
- Test it out
|
||||
- Report back your issues
|
||||
- Suggest improvements
|
||||
- Issues / Discussions are open
|
||||
- Issues / Discussions are open and active
|
||||
- If you want to get involved, please do!
|
||||
- There's plenty of work to do
|
||||
- And I can't do it alone!
|
||||
|
|
Loading…
Reference in a new issue