creo que nunca se usa crontab realmente.
Yo hice un hello world simple 馃槂
Bienvenida
Celery 驴Qu茅 es, para qu茅 sirve, c贸mo se usa?
Repositorio del proyecto
Arquitecturas de software basadas en mensajer铆a y colas de tareas
Brokers de tareas: Servidores de mensajer铆a y formas de usarlos
驴Cu谩ndo debemos usar Celery?
Reto: Casos de uso de Celery
Bot de Slack
驴C贸mo funciona un bot?
C贸mo funciona el API de Slack para programaci贸n de bots (y parecidos y diferencias con otros APIs)
驴C贸mo crear un bot reactivo?
Reto: posibles aplicaciones de bots de Slack, buscar ejemplos y entender c贸mo se llevar铆an a cabo
Reto: modificar el bot b谩sico y crear alguno que responda a a alg煤n tipo de petici贸n o muestre algo
Brokers de mensajer铆a
驴Qu茅 es un broker de mensajer铆a y cu谩ndo debe usarse?
Conceptos: mecanismos de publicaci贸n/suscripci贸n. Canales. Intercambiadores
Brokers de mensajer铆a open source
Python con RabbitMQ uso b谩sico de la terminal
Comparaci贸n de diferentes brokers de mensajer铆a para trabajar con Celery
Reto: Crear una peque帽a aplicaci贸n cliente-servidor que use RabbitMQ desde Python
Celery y brokers de mensajer铆a
Creando un entorno de desarrollo para Celery
Instalaci贸n y creaci贸n de un programa b谩sico pub/sub
C贸mo usar Celery para programar un robot de Slack: dise帽o y comienzo de la implementaci贸n
Monitorizaci贸n de tareas
Solucionando problemas
Reto: implementaci贸n y despliegue b谩sico de un bot de Slack
Enrutado de tareas
Conceptos: enrutado de tareas y por qu茅 se necesita
Enrutado manual
Mensajer铆a en Celery: uso de Kombu
Enrutado autom谩tico
Reto: dise帽o de mecanismos de enrutado para un bot de Slack
Integraci贸n y despliegue en la nube
Estructura de mensajes en Celery y resultados de tareas
Tareas peri贸dicas con Celery
Configuraci贸n de sistemas en la nube
Contenedores
Despliegue en un PaaS: Heroku
Uso de Celery con Node.js
Reto: despliegue en la nube (usando cuentas gratuitas)
Conclusiones
Despedida, conclusiones y a d贸nde ir desde aqu铆
You don't have access to this class
Keep learning! Join and start boosting your career
Learning how to schedule periodic tasks is an essential skill for automating processes that require constant execution, such as data collection or server maintenance. In this content, you will discover how to handle periodic tasks using Celery, a powerful Python task manager that makes it easy to schedule and run jobs in the background.
Celery is a Python library designed to manage tasks in an asynchronous and scheduled manner. It allows you to define specific tasks and schedule their execution at regular intervals, which is useful when you need repetitive processes without human intervention. Some key aspects of Celery include:
celery.beat
, which allows you to configure tasks to run automatically on a set schedule.First, you must import the necessary tools to work with Celery. Here's how to structure your script to create a recurring task:
from celery import Celeryfrom celery.schedules import crontab
app = Celery('app_name', broker='redis://localhost:6379/0')
# Set up periodic taskapp.conf.beat_schedule = { ' task_name': { ' task': 'module_name.specific_task', ' schedule': crontab(minute=0, hour='*/1'), # Run every hour },}
Suppose you need to collect data from a web page at regular intervals. You can use libraries like beautifulsoup4
to parse the HTML and extract the information you need. This is complemented with Celery to schedule periodic data download.
import requestsfrom bs4 import BeautifulSoup
def download_data(): url = " https://ejemplo.com/pagina-deseada" response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser')
# Extract page-specific data extract_data = soup.find_all('div', class_='class-specific')
with open('data.json', 'w') as file: file.write(str(extract_data))
To start the tasks, you must run Celery with a worker and, if you are scheduling periodic tasks, you also need to start the beat scheduler.
Start the worker: Process that executes the tasks scheduled by Celery.
celery -A application_name worker --loglevel=info
Start the beat scheduler: It is in charge of sending the periodic tasks to the worker.
celery -A application_name beat --loglevel=info
Celery is a powerful tool that can handle multiple tasks and schedule them efficiently, offering an ideal solution for projects that require automation and background processing. With practice and a good approach, you can master the use of periodic tasks and improve the efficiency of your applications.
Contributions 1
Questions 0
creo que nunca se usa crontab realmente.
Yo hice un hello world simple 馃槂
Want to see more contributions, questions and answers from the community?