5

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 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.