Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Tarefas assíncronas com django e celery
Allisson Azevedo
June 11, 2013
Programming
1
23k
Tarefas assíncronas com django e celery
Slides da palestra no mutirão python:
https://plus.google.com/events/c4a18aljra59dqf56t1lac89o4k
Allisson Azevedo
June 11, 2013
Tweet
Share
More Decks by Allisson Azevedo
See All by Allisson Azevedo
Programação Assíncrona com Asyncio
allisson
0
40
Crawleando sites com NodeJS
allisson
0
130
Introdução a linguagem Go
allisson
0
200
Docker + Django
allisson
5
420
Construindo um micro framework web em Python
allisson
0
180
Consumindo API's OAuth{1,2} com Python
allisson
1
120
Deploy completo de uma aplicação Django
allisson
6
360
Desenvolvimento Web com Django
allisson
0
110
Otimizando sites com o nosql redis
allisson
4
110
Other Decks in Programming
See All in Programming
Angular‘s Future without NgModules: Architectures with Standalone Components @enterJS
manfredsteyer
PRO
0
240
From Java through Scala to Clojure
lagenorhynque
0
230
NEWT.net: Frontend Technology Selection
xpromx
0
250
Deep Dive Into Google Zanzibar and its Concepts for Authorization Scenarios
dschenkelman
1
140
こそこそアジャイル導入しようぜ!
ichimichi
0
1.2k
競プロのすすめ
uya116
0
670
IE Graduation Certificate
jxck
6
4.8k
Lancersをコンテナへ本番移行する取り組み
rvirus0817
1
390
Value and Record Types
hschwentner
0
550
"What's new in Swift"の要約 / swift_5_7_summary
uhooi
1
330
Baseline Profilesでアプリのパフォーマンスを向上させる / Improve app performance with Baseline Profiles
numeroanddev
0
250
git on intellij
hiroto_kitamura
0
170
Featured
See All Featured
What's new in Ruby 2.0
geeforr
336
30k
Agile that works and the tools we love
rasmusluckow
319
19k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
351
21k
Bootstrapping a Software Product
garrettdimon
296
110k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
237
19k
StorybookのUI Testing Handbookを読んだ
zakiyama
5
2.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
224
49k
Why Our Code Smells
bkeepers
PRO
324
55k
Web development in the modern age
philhawksworth
197
9.3k
How GitHub Uses GitHub to Build GitHub
holman
465
280k
The Cult of Friendly URLs
andyhume
68
4.8k
Become a Pro
speakerdeck
PRO
3
840
Transcript
TAREFAS ASSÍNCRONAS COM DJANGO E CELERY Allisson Azevedo Monday, June
10, 13
ALLISSON AZEVEDO Graduado em Licenciatura em Computação Desenvolvedor Web http://speakerdeck.com/allisson
http://slideshare.net/allisson http://github.com/allisson http://youtube.com/user/allissonazevedo Monday, June 10, 13
Monday, June 10, 13
Monday, June 10, 13
PORQUE EU PRECISO DE UM TASK/JOB QUEUE? Necessidade de processar
uma tarefa fora do ciclo de requisição e reposta Processamento de vídeo/imagens Envio de e-mails Geração de relatórios complexos Comunicação com API’s externas (twitter, facebook) Monday, June 10, 13
PORQUE EU PRECISO DE UM TASK/JOB QUEUE? Agendar tarefas (substituir
o cron) Trabalhar com indexação de um search engine Monday, June 10, 13
COMO FUNCIONA? Client Quem gera a tarefa Message Broker Gerencia
a fila de tarefas Worker Recebe as tarefas do Broker e executa as mesmas Monday, June 10, 13
COMO FUNCIONA? Result Store Onde são guardados os resultados das
tarefas Monday, June 10, 13
CELERY “Distributed Task Queue” Escrito em python Integração com os
principais frameworks python (django, pyramid, flask, web2py, tornado) Broker Backends (rabbitmq, redis, sqlalchemy, django, mongodb) Result Store Backends (Redis, memcached, MongoDB) Monday, June 10, 13
QUAL BROKER USAR? RabbitMQ (http://stackoverflow.com/a/9176046) Redis Não use o broker
como result store Monday, June 10, 13
INTEGRANDO COM O DJANGO pip install django-celery Adicione o djcelery
no INSTALLED_APPS Adicione as linhas no settings.py import djcelery djcelery.setup_loader() Monday, June 10, 13
INTEGRANDO COM O DJANGO Selecione o broker BROKER_URL = 'redis://localhost:6379/0'
#Redis Inicie o worker python manage.py celery worker --loglevel=info Monday, June 10, 13
INTEGRANDO COM O DJANGO Em seus projetos, crie um arquivo
chamado tasks.py Monday, June 10, 13
INTEGRANDO COM O DJANGO from celery import task @task() def
add(x, y): return x + y Monday, June 10, 13
INTEGRANDO COM O DJANGO Rode a task Monday, June 10,
13
INTEGRANDO COM O DJANGO >>> from celerytest.tasks import add >>>
add.delay(2, 2) >>> add.apply_async((2, 2)) Monday, June 10, 13
MÃO NA MASSA! https://github.com/allisson/django-social-monitor- example Monday, June 10, 13
Monday, June 10, 13
OBRIGADO! Monday, June 10, 13