Giter Site home page Giter Site logo

celery-base's Introduction

docker run --name rabbit -p 5672:5672 -d rabbitmq

En app hacer los archivos

  • celery.py
  • celeryconfig.py
  • task.py

En celery.py

import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')

broker = 'pyamqp://guest@localhost//'
celery_app = Celery('task', include = ['app.task'], broker=broker)

celery_app.config_from_object('django.conf:settings', namespace='CELERY')

celery_app.autodiscover_tasks()

from celery.schedules import crontab

En celeryconfig.py

CELERY_IMPORTS = ("tasks", )
CELERY_RESULT_BACKEND = "amqp"
BROKER_URL = "amqp://guest:guest@localhost:5672//"
CELERY_TASK_RESULT_EXPIRES = 300

En task.py

from app.celery import celery_app

@celery_app.task
def tu_funcion(saludo):
    print(saludo)

En settings.py agregar la configuracion de celery

...

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')

CELERY_TIMEZONE = 'America/Mexico_City'
CELERY_TASK_TRACK_STARTED = True
CELERY_IMPORTS=("app.task")

...

En app/__init__.py agregar

from __future__ import absolute_import, unicode_literals

from .celery import celery_app

__all__ = ('celery_app',)

Las funciones va en task.py
Ejemplo para mandarlas a llamar en apis/api.py

ejecutar_el = datetime.datetime.utcnow() + datetime.timedelta(seconds=30)
tu_funcion.apply_async(args=['hola que tal'], eta=ejecutar_el)

Para poner a escuchar a celery en la consola
A la altura de manage.py

celery -A app.task worker -l info  

img-1
img-2
img-3
img-4
img-5
img-6
img-7
img-8
img-9
img-10
img-11

celery-base's People

Contributors

ojitos369 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.