Create cronjob for django management command async process

 Recently i have facing some problem with cronjob set with django project 


In my case i need to pull the data from external api and save the data in every minute then i write this code

Please do following steps.

1. Create management folder in your app folder and in management folder add commands folder.

add file e.g import_jobs.py

from __future__ import unicode_literals, absolute_import, division
from django.core.management.base import BaseCommand
import logging


logger = logging.getLogger(__name__)

#-------------------------------------------------------------------------------
# Command
#-------------------------------------------------------------------------------



class Command(BaseCommand):

help = "Add Jobs from BH Portal"

#---------------------------------------------------------------------------
# handle
#---------------------------------------------------------------------------
def handle(self, *args, **options):
# add your logic here
pass 
 

Then go to terminal and write command

crontab -e

* * * * * /home/ubuntu/workspace/<projectname>/venv/bin/python /home/ubuntu/workspace/<projectname>/manage.py add_jobs > /home/techstriker/workspace/mergent/job.log


then save this file and Please check your django project 

Done!

CHEERS!!



 

Comments

Popular posts from this blog

Google Calendar api with django application

Google recaptcha integration with django applicaton