forked from slides/empowering-django-with-background-workers
Slide tweaks from script tweaks
This commit is contained in:
parent
11a6134b74
commit
652581ee82
2 changed files with 145 additions and 55 deletions
29
public/celery.svg
Normal file
29
public/celery.svg
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 24.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
viewBox="0 0 519.27 214.14" style="enable-background:new 0 0 519.27 214.14;" xml:space="preserve">
|
||||||
|
<style type="text/css">
|
||||||
|
.st0{fill:#B6DE64;}
|
||||||
|
.st1{clip-path:url(#SVGID_2_);}
|
||||||
|
.st2{fill:#A9CC54;}
|
||||||
|
.st3{fill:none;stroke:#DDF4A4;stroke-width:49;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;}
|
||||||
|
</style>
|
||||||
|
<path class="st0" d="M493.54,171.25c-35.63,0-64.52-28.89-64.52-64.52s28.89-64.52,64.52-64.52c3.85,0,7.62,0.36,11.29,1
|
||||||
|
L493.54,5.45H104.46v0.02C49.24,6.51,4.78,51.59,4.78,107.07c0,55.47,44.45,100.56,99.68,101.59v0.02h389.07l11.29-38.44
|
||||||
|
C501.16,170.89,497.39,171.25,493.54,171.25z"/>
|
||||||
|
<g>
|
||||||
|
<defs>
|
||||||
|
<path id="SVGID_1_" d="M493.54,171.25c-35.63,0-64.52-28.89-64.52-64.52s28.89-64.52,64.52-64.52c3.85,0,7.62,0.36,11.29,1V5.45
|
||||||
|
H104.46v0.02C49.24,6.51,4.78,51.59,4.78,107.07c0,55.47,44.45,100.56,99.68,101.59v0.02h389.07l11.29-38.44
|
||||||
|
C501.16,170.89,497.39,171.25,493.54,171.25z"/>
|
||||||
|
</defs>
|
||||||
|
<clipPath id="SVGID_2_">
|
||||||
|
<use xlink:href="#SVGID_1_" style="overflow:visible;"/>
|
||||||
|
</clipPath>
|
||||||
|
<g class="st1">
|
||||||
|
<rect x="-23.16" y="55.58" class="st2" width="451.66" height="51.1"/>
|
||||||
|
<rect x="-23.16" y="157.59" class="st2" width="530.98" height="72.35"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
<path class="st3" d="M493.54,184.23c-43.94,0-79.56-33.62-79.56-77.56s35.62-76.56,79.56-76.56"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
171
slides.md
171
slides.md
|
@ -40,8 +40,7 @@ addons:
|
||||||
layout: center
|
layout: center
|
||||||
---
|
---
|
||||||
|
|
||||||
# Django isn't _just_ for websites
|
# Django is a web framework
|
||||||
|
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart LR
|
flowchart LR
|
||||||
|
@ -54,9 +53,7 @@ flowchart LR
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.mermaid {
|
.mermaid {
|
||||||
margin-top: 2rem;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
transform: scale(1.5);
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
@ -64,52 +61,66 @@ flowchart LR
|
||||||
layout: full
|
layout: full
|
||||||
---
|
---
|
||||||
|
|
||||||
|
# Django isn't _just_ for websites
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart BT
|
flowchart TD
|
||||||
U[User 🧑💻]
|
U[User 🧑💻]
|
||||||
D[\Django/]
|
D[\Django/]
|
||||||
DB[(Database)]
|
DB[(Database)]
|
||||||
C[(Cache)]
|
|
||||||
E>Email]
|
E>Email]
|
||||||
EA[External API]
|
EA[External API]
|
||||||
V[[Video Transcode]]
|
V[[Video Transcoding]]
|
||||||
ML((Machine Learning))
|
R[Reporting]
|
||||||
|
ML((Machine<br>Learning))
|
||||||
|
|
||||||
U---->|Request|D
|
U<--->D
|
||||||
D---->|Response|U
|
|
||||||
|
|
||||||
D-.-DB & E & EA & V & ML & C
|
D---DB
|
||||||
|
D-..-E & EA & V & R & ML
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.mermaid {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: full
|
layout: full
|
||||||
---
|
---
|
||||||
|
|
||||||
|
# Background Workers!
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart BT
|
flowchart TD
|
||||||
U[User 🧑💻]
|
U[User 🧑💻]
|
||||||
D[\Django/]
|
D[\Django/]
|
||||||
DB[(Database)]
|
|
||||||
C[(Cache)]
|
|
||||||
E>Email]
|
E>Email]
|
||||||
EA[External API]
|
EA[External API]
|
||||||
V[[Video Transcode]]
|
V[[Video Transcoding]]
|
||||||
ML((Machine Learning))
|
R[Reporting]
|
||||||
B{{Background Processing}}
|
ML((Machine<br>Learning))
|
||||||
|
|
||||||
U--->|Request|D
|
B{{<strong>Background Processing</strong>}}
|
||||||
D--->|Response|U
|
|
||||||
|
|
||||||
D---B
|
U<-->D
|
||||||
|
|
||||||
D-.-C & DB
|
D-..-B
|
||||||
|
|
||||||
B---E & V & ML & EA
|
B---E & EA & V & R & ML
|
||||||
B---C & DB
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.mermaid {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: cover
|
layout: section
|
||||||
---
|
---
|
||||||
|
|
||||||
# Background Workers?
|
# Background Workers?
|
||||||
|
@ -126,11 +137,11 @@ flowchart LR
|
||||||
R2{Runner}
|
R2{Runner}
|
||||||
R3{Runner}
|
R3{Runner}
|
||||||
|
|
||||||
D<--->S<-..->R1 & R2 & R3
|
D<----->S<-....->R1 & R2 & R3
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: cover
|
layout: section
|
||||||
---
|
---
|
||||||
|
|
||||||
# When?
|
# When?
|
||||||
|
@ -139,8 +150,6 @@ layout: cover
|
||||||
layout: fact
|
layout: fact
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart BT
|
flowchart BT
|
||||||
D[\Django/]
|
D[\Django/]
|
||||||
|
@ -163,14 +172,14 @@ flowchart BT
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: cover
|
layout: section
|
||||||
---
|
---
|
||||||
|
|
||||||
# Background Workers _in Django_
|
# Background Workers _in Django_
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: cover
|
layout: cover
|
||||||
background: https://docs.celeryq.dev/en/stable/_static/celery_512.png
|
background: /celery.svg
|
||||||
---
|
---
|
||||||
|
|
||||||
# Celery!
|
# Celery!
|
||||||
|
@ -178,6 +187,7 @@ background: https://docs.celeryq.dev/en/stable/_static/celery_512.png
|
||||||
<style>
|
<style>
|
||||||
.slidev-layout {
|
.slidev-layout {
|
||||||
background: white;
|
background: white;
|
||||||
|
background-size: contain !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
@ -216,6 +226,29 @@ background: https://images.unsplash.com/photo-1522096823084-2d1aa8411c13?q=80&w=
|
||||||
layout: center
|
layout: center
|
||||||
---
|
---
|
||||||
|
|
||||||
|
# Sending an email
|
||||||
|
|
||||||
|
```python {all|7|8|9-14|all}
|
||||||
|
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]
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
layout: center
|
||||||
|
---
|
||||||
|
|
||||||
```python {all|18|19|10|11-16|all|18-19|all}
|
```python {all|18|19|10|11-16|all|18-19|all}
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
|
@ -228,7 +261,7 @@ from wagtail.models import Page
|
||||||
def send_email_to_user(page: Page, user: User):
|
def send_email_to_user(page: Page, user: User):
|
||||||
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
||||||
send_mail(
|
send_mail(
|
||||||
subject="A page has been published",
|
subject=f"A change to {page.title} has been published",
|
||||||
message=email_content
|
message=email_content
|
||||||
from_email=None, # Use the default sender email
|
from_email=None, # Use the default sender email
|
||||||
recipient_list=[user.email]
|
recipient_list=[user.email]
|
||||||
|
@ -242,7 +275,7 @@ for user in page.subscribers.iterator():
|
||||||
layout: center
|
layout: center
|
||||||
---
|
---
|
||||||
|
|
||||||
# A problem
|
# Using <span v-click.hide="1">RQ</span><span v-click="1"><s class="opacity-60">RQ</s> Celery</span>
|
||||||
|
|
||||||
````md magic-move
|
````md magic-move
|
||||||
```python
|
```python
|
||||||
|
@ -257,7 +290,7 @@ from wagtail.models import Page
|
||||||
def send_email_to_user(page: Page, user: User):
|
def send_email_to_user(page: Page, user: User):
|
||||||
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
||||||
send_mail(
|
send_mail(
|
||||||
subject="A page has been published",
|
subject=f"A change to {page.title} has been published",
|
||||||
message=email_content
|
message=email_content
|
||||||
from_email=None, # Use the default sender email
|
from_email=None, # Use the default sender email
|
||||||
recipient_list=[user.email]
|
recipient_list=[user.email]
|
||||||
|
@ -280,7 +313,7 @@ from my_celery_config import app
|
||||||
def send_email_to_user(page: Page, user: User):
|
def send_email_to_user(page: Page, user: User):
|
||||||
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
||||||
send_mail(
|
send_mail(
|
||||||
subject="A page has been published",
|
subject=f"A change to {page.title} has been published",
|
||||||
message=email_content
|
message=email_content
|
||||||
from_email=None, # Use the default sender email
|
from_email=None, # Use the default sender email
|
||||||
recipient_list=[user.email]
|
recipient_list=[user.email]
|
||||||
|
@ -291,6 +324,12 @@ for user in page.subscribers.iterator():
|
||||||
```
|
```
|
||||||
````
|
````
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.slidev-vclick-hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: image
|
layout: image
|
||||||
image: /situation.png
|
image: /situation.png
|
||||||
|
@ -311,7 +350,7 @@ layout: fact
|
||||||
|
|
||||||
# `django.tasks`
|
# `django.tasks`
|
||||||
|
|
||||||
<div class="absolute right-1/2 translate-x-1/2 mt-6">
|
<div class="absolute right-1/2 translate-x-1/2 mt-12">
|
||||||
<QRCode
|
<QRCode
|
||||||
:width="120"
|
:width="120"
|
||||||
:height="120"
|
:height="120"
|
||||||
|
@ -338,6 +377,8 @@ class: flex items-center text-xl
|
||||||
layout: center
|
layout: center
|
||||||
---
|
---
|
||||||
|
|
||||||
|
# <span v-click.hide="1">Using Celery</span><span v-click="1">Using <code>django.tasks</code></span>
|
||||||
|
|
||||||
````md magic-move
|
````md magic-move
|
||||||
```python
|
```python
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -352,7 +393,7 @@ from my_celery_config import app
|
||||||
def send_email_to_user(page: Page, user: User):
|
def send_email_to_user(page: Page, user: User):
|
||||||
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
||||||
send_mail(
|
send_mail(
|
||||||
subject="A page has been published",
|
subject=f"A change to {page.title} has been published",
|
||||||
message=email_content
|
message=email_content
|
||||||
from_email=None, # Use the default sender email
|
from_email=None, # Use the default sender email
|
||||||
recipient_list=[user.email]
|
recipient_list=[user.email]
|
||||||
|
@ -375,7 +416,7 @@ from django.tasks import task
|
||||||
def send_email_to_user(page: Page, user: User):
|
def send_email_to_user(page: Page, user: User):
|
||||||
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
||||||
send_mail(
|
send_mail(
|
||||||
subject="A page has been published",
|
subject=f"A change to {page.title} has been published",
|
||||||
message=email_content
|
message=email_content
|
||||||
from_email=None, # Use the default sender email
|
from_email=None, # Use the default sender email
|
||||||
recipient_list=[user.email]
|
recipient_list=[user.email]
|
||||||
|
@ -386,6 +427,12 @@ for user in page.subscribers.iterator():
|
||||||
```
|
```
|
||||||
````
|
````
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.slidev-vclick-hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: center
|
layout: center
|
||||||
---
|
---
|
||||||
|
@ -395,11 +442,12 @@ from django.contrib.auth.models import User
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
email_content = render_to_string("email-template.html", {"page": page})
|
from wagtail.models import Page
|
||||||
|
|
||||||
for user in page.subscribers.iterator():
|
for user in page.subscribers.iterator():
|
||||||
|
email_content = render_to_string("notification-email.html", {"user": user, "page": page})
|
||||||
send_mail(
|
send_mail(
|
||||||
subject="The page has changed",
|
subject=f"A change to {page.title} has been published",
|
||||||
message=email_content
|
message=email_content
|
||||||
from_email=None, # Use the default sender email
|
from_email=None, # Use the default sender email
|
||||||
recipient_list=[user.email]
|
recipient_list=[user.email]
|
||||||
|
@ -417,7 +465,6 @@ EMAIL_BACKEND = "django.core.mail.backends.tasks.SMTPEmailBackend"
|
||||||
|
|
||||||
</v-click>
|
</v-click>
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: image-right
|
layout: image-right
|
||||||
image: /soon.png
|
image: /soon.png
|
||||||
|
@ -426,34 +473,31 @@ class: flex justify-center text-2xl flex-col
|
||||||
|
|
||||||
# Q: Why something new?
|
# Q: Why something new?
|
||||||
|
|
||||||
<v-click>
|
|
||||||
|
|
||||||
### A: It doesn't have to be
|
|
||||||
|
|
||||||
</v-click>
|
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: image-right
|
layout: image-right
|
||||||
image: https://images.unsplash.com/photo-1525683879097-8babce1c602a?q=80&w=1335&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D
|
image: https://images.unsplash.com/photo-1525683879097-8babce1c602a?q=80&w=1335&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D
|
||||||
class: flex justify-center text-2xl flex-col
|
class: flex justify-center text-xl flex-col
|
||||||
---
|
---
|
||||||
|
|
||||||
# Q: Why something built-in?
|
# Q: Why something built-in?
|
||||||
|
|
||||||
- Improve interoperability
|
|
||||||
- Reduce cognitive load
|
|
||||||
- Reduce barrier to entry
|
- Reduce barrier to entry
|
||||||
|
- Reduce cognitive load
|
||||||
|
- Reduce complexity for smaller projects
|
||||||
|
- Improve interoperability
|
||||||
|
- Use what's already there
|
||||||
|
- A common API
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: center
|
layout: center
|
||||||
transition: fade
|
transition: fade
|
||||||
---
|
---
|
||||||
|
|
||||||
![](/postgres.png){.max-h-48.mx-auto}
|
![](/celery.svg){.h-32.mx-auto}
|
||||||
|
|
||||||
## vs
|
## vs
|
||||||
|
|
||||||
![](https://docs.celeryq.dev/en/stable/_static/celery_512.png){.max-h-32.mx-auto}
|
![](/postgres.png){.h-36.mx-auto}
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -468,11 +512,11 @@ transition: fade
|
||||||
layout: center
|
layout: center
|
||||||
---
|
---
|
||||||
|
|
||||||
![](/postgres.png){.max-h-48.mx-auto}
|
![](/elasticsearch.png){.h-32.mx-auto}
|
||||||
|
|
||||||
## vs
|
## vs
|
||||||
|
|
||||||
![](/elasticsearch.png){.max-h-32.mx-auto}
|
![](/postgres.png){.max-h-36.mx-auto}
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -503,7 +547,7 @@ layout: section
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: cover
|
layout: cover
|
||||||
background: https://docs.celeryq.dev/en/stable/_static/celery_512.png
|
background: /celery.svg
|
||||||
---
|
---
|
||||||
|
|
||||||
# Is this the end?
|
# Is this the end?
|
||||||
|
@ -511,6 +555,7 @@ background: https://docs.celeryq.dev/en/stable/_static/celery_512.png
|
||||||
<style>
|
<style>
|
||||||
.slidev-layout {
|
.slidev-layout {
|
||||||
background: white;
|
background: white;
|
||||||
|
background-size: contain !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
@ -531,6 +576,7 @@ class: flex justify-center flex-col text-xl
|
||||||
- Cron-based scheduling
|
- Cron-based scheduling
|
||||||
- Task timeouts
|
- Task timeouts
|
||||||
- Swappable argument serialization
|
- Swappable argument serialization
|
||||||
|
- ...
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: cover
|
layout: cover
|
||||||
|
@ -545,11 +591,26 @@ layout: section
|
||||||
|
|
||||||
# What's next?
|
# What's next?
|
||||||
|
|
||||||
|
<v-click>
|
||||||
|
|
||||||
|
## `pip install django-tasks`
|
||||||
|
|
||||||
|
<div class="absolute right-1/2 translate-x-1/2 mt-12">
|
||||||
|
<QRCode
|
||||||
|
:width="120"
|
||||||
|
:height="120"
|
||||||
|
data="https://pypi.org/project/django-tasks/"
|
||||||
|
:dotsOptions="{ color: 'white' }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</v-click>
|
||||||
|
|
||||||
---
|
---
|
||||||
layout: end
|
layout: end
|
||||||
---
|
---
|
||||||
|
|
||||||
QUESTIONS?
|
END
|
||||||
|
|
||||||
<div class="absolute right-1/2 bottom-4 translate-x-1/2">
|
<div class="absolute right-1/2 bottom-4 translate-x-1/2">
|
||||||
<QRCode
|
<QRCode
|
||||||
|
|
Loading…
Reference in a new issue