celery / cronjobs를 사용하여 5 분마다 데이터베이스에 사용자를 추가하는 방법은 무엇입니까?
내 코드가 작동하지 않습니다.
@periodic_task(run_every=crontab( minute='5', day_of_week="*"))
def create_user():
try
user = registrations.objects.get(username='username',password='password')
except User.DoesNotExist:
user = registrations(username='username', password='password')
user.save()
이런 식으로 할 수 있다고 생각합니다.
from uuid import uuid4
@periodic_task(run_every=crontab(minute='*/5'))
def create_user():
try:
username = uuid4().hex # username should be unique
user = registrations(username=username,password='pass123')
user.save()
# user = User.objects.create(username=username,password='pass123') # If you are using Django auth user model, which you should. No need to call .save() on this
except Exception, e:
print str(e) # Log the error
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다