1
votes

I have written this task in tasks.py file which is under my django apps directory myapp.

#periodic task that run every minute
@periodic_task(run_every=(crontab(hour="*", minute="*", day_of_week="*")))
def news():
    '''
    Grab url
    '''
    logger.info("Start task")
    now =  datetime.now()
    urls = []
    urls.append(crawler()) #crawler return dic obj
    for url_dic in list(reversed(urls)):
        for title, url  in url_dict.items():
            #Save all the scrape url in database
            Url.objects.create(title=headline, url=url)

    logger.info("Task finished: result = %s" %url)

The main objectives of this task is to push the url and title to django database every minute

To run this celery task we need to invoke these commands using django ./manage utility how to run these commands as a daemon and I am planning to host this app in heroku

python manage.py celeryd --verbosity=2 --loglevel=DEBUG
python manage.py celerybeat --verbosity=2 --loglevel=DEBUG

but I need to run these two commands command as a daemon in background, How can we run this commands as a daemon so that my celery tasks can run.

1

1 Answers

0
votes

A fast fix will be to put "&" after your commands i.e.

python manage.py celeryd --verbosity=2 --loglevel=DEBUG &
python manage.py celerybeat --verbosity=2 --loglevel=DEBUG &

After hitting enter this tasks will act as daemon and still print out the useful debug info. So this is great for initial stage and sometimes small applications that do not rely heavily on celery.

For development purpose i will suggest using supervisor .See THIS POST that gives realy nice info for celery, django and supervisor integration. Read the: "Running Celery workers as daemons" part of the post.