periodic task in celery using python without django

1.4k views Asked by At

Hello all i am newbie to celery and python. i am creating a simple task using rabbitmq-server. But i have no idea how to achieve periodic task using celery beat in python. I search but every where i get periodic task with django.

i use this code as tasks.py: from celery import Celery from time import strftime

app = Celery('tasks',broker='pyamqp://guest@localhost//')

@app.task
def show_time():
    return strftime('%Y-%m-%d %H:%M:%S')

run_task.py:

from tasks import show_time
show_time.delay()

Thanks for you time.

1

There are 1 answers

0
Manish Yadav On

finally after some more concise search i have found solution

from celery import Celery
from kombu import Queue, Exchange



class Config(object):
    CELERY_QUEUES = (
        Queue(
            'try',
            exchange=Exchange('try'),
            routing_key='try',
        ),
    )
celery =Celery('tasks',broker='pyamqp://guest@localhost//')

celery.config_from_object(Config)


celery.conf.beat_schedule = {
    'planner': {
        'task': 'task_planner.some_task',
        'schedule': 5.0,
    },
}


@celery.task(queue='try')
def some_task():
    print('Hooray')

and run command : celery -A task_planner worker -l info -B