https://github.com/kraiz/django-crontab
http://django-cron.readthedocs.org/en/latest/installation.html
Ubuntu에 django-crontab 처음 사용해 볼 때, 동작확인 할 수 있는 튜토리얼 입니다.
기본 명령어 모음
sudo apt-get update sudo apt-get -y install vim sudo apt-get -y install build-essential python-all-dev python-dev python-setuptools libpq-dev libev-dev sudo apt-get -y install git openssh-server sudo easy_install pip sudo apt-get install -y python-virtualenv virtualenvwrapper sudo apt-get install -y libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms1-dev libwebp-dev mkdir ~/.virtualenvs export WORKON_HOME=$HOME/.virtualenvs export PIP_VIRTUALENV_BASE=$WORKON_HOME (terminal 재시작;;) cd ~/.virtualenvs mkvirtualenv temp_env |
기본 패키지 설치
pip install django
pip install django-crontab
프로젝트 생성
django-admin.py startproject project
python manage.py migrate
python manage.py createsuperuser
myapp 만듦
cd project
python manage.py startapp myapp
파일들 수정
myapp/models.py
from django.db import models # Create your models here. class CronLog(models.Model): date = models.DateTimeField(auto_now_add=True, blank=True) def __unicode__(self): return self.date.ctime() |
myapp/admin.py
from django.contrib import admin from myapp.models import * # Register your models here. admin.site.register(CronLog) |
myapp/cron.py(create)
from myapp.models import * def my_scheduled_job(): CronLog.objects.create() |
project/settings.py
... INSTALLED_APPS = ( ... 'django_crontab', 'myapp', ) CRONJOBS = [ ('*/5 * * * *', 'myapp.cron.my_scheduled_job') ] ... |
myapp migration 후 crontab 등록, 실행
python manage.py makemigrations
python manage.py migrate
python manage.py crontab add
python manage.py runserver
댓글 없음:
댓글 쓰기