Question

hey guys i am new to celery. i am working on periodic task scheduling. I have configured my celeryconfig.py as follow:

from datetime import timedelta

BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = "redis"
CELERY_REDIS_HOST = "localhost"
CELERY_REDIS_PORT = 6379
CELERY_REDIS_DB = 0
CELERY_IMPORTS=("mytasks")
CELERYBEAT_SCHEDULE={'runs-every-60-seconds' :
                        {
                                'task': 'mytasks.add',
                                'schedule': timedelta(seconds=60),
                                'args':(16,16)
                        },
                    }

and mytask.pyas follow:

from celery import Celery

celery = Celery("tasks",
                broker='redis://localhost:6379/0',
                backend='redis')


@celery.task
def add(x,y):
        return x+y

@celery.task
def mul(x,y):
        return x*y

when i am running celery beat -s celerybeat-schedule then i am getting

Configuration -> . broker -> redis://localhost:6379/0 . loader -> celery.loaders.default.Loader . scheduler -> celery.beat.PersistentScheduler . db -> celerybeat-schedule . logfile -> [stderr]@INFO . maxinterval -> now (0s) [2012-08-28 12:27:17,825: INFO/MainProcess] Celerybeat: Starting... [2012-08-28 12:28:00,041: INFO/MainProcess] Scheduler: Sending due task mytasks.add [2012-08-28 12:29:00,057: INFO/MainProcess] Scheduler: Sending due task mytasks.add [2012-08-28 12:30:00,064: INFO/MainProcess] Scheduler: Sending due task mytasks.add [2012-08-28 12:31:00,097: INFO/MainProcess] Scheduler: Sending due task mytasks.add

now i am not getting that i have passed arguments (16,16) then how i can get the answer of this function add(x,y)

Was it helpful?

Solution

I'm not sure I quite understand what you have asked, but from what I can tell, your issue may be one of the following:

1) Are you running celeryd (the worker daemon)? If not, did you start a celery worker in a terminal? Celery beat is a task scheduler. It is not a worker. Celerybeat only schedules the tasks (i.e. places them in a queue for a worker to eventually consume).

2) How did you plan on viewing the results? Are they being saved somewhere? Since you have set your results backend to redis, the results are at least temporarily stored in the redis results backend

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top