{"id":27038377,"url":"https://github.com/neulhan/cron-tutorial","last_synced_at":"2025-04-05T02:31:25.688Z","repository":{"id":41914992,"uuid":"253807461","full_name":"Neulhan/cron-tutorial","owner":"Neulhan","description":null,"archived":false,"fork":false,"pushed_at":"2022-04-22T23:17:26.000Z","size":27,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-03T16:31:56.983Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Neulhan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-07T13:50:59.000Z","updated_at":"2020-04-07T15:34:45.000Z","dependencies_parsed_at":"2022-08-11T21:40:26.757Z","dependency_job_id":null,"html_url":"https://github.com/Neulhan/cron-tutorial","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neulhan%2Fcron-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neulhan%2Fcron-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neulhan%2Fcron-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neulhan%2Fcron-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neulhan","download_url":"https://codeload.github.com/Neulhan/cron-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247279332,"owners_count":20912866,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-05T02:30:57.996Z","updated_at":"2025-04-05T02:31:25.618Z","avatar_url":"https://github.com/Neulhan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 설치\n먼저 Django 크론탭을 한 번 설치해봅시다.  \n\n`pipenv install django_crontab` or `(venv) ~/dev/django/myproject pip install django_crontab`  \n환경에 맞게 잘 깔아줍시다.\n\n`django_crontab` 을 `INSTALLED_APPS` 에 추가해줍시다. \n\n```python\n# settings.py\n\nINSTALLED_APPS = [\n    \"django.contrib.admin\",\n    \"django.contrib.auth\",\n    \"django.contrib.contenttypes\",\n    \"django.contrib.sessions\",\n    \"django.contrib.messages\",\n    \"django.contrib.staticfiles\",\n    \"django_crontab\",\n]\n``` \n\n`python manage.py crontab show` 를 입력해서 잘 설치되었는지 체크해봅시다.\n\n```bash\n ~/dev/django/cron_tutorial   master ●  python manage.py crontab show\nCurrently active jobs in crontab:\n```  \n\n## 사용하기\ndjango crontab은 settings.py 에 등록된 task를 주기적으로 실행해줍니다.\n\nCRONJOBS에 task 를 등록해서 사용해봅시다.\n\n```python\n# settings.py\nCRONJOBS = [\n    (\"* * * * *\", \"utils.a.function_a\", \"\u003e\u003e log.txt\")\n]\n```\nsettings.CRONJOBS 는 리스트이고 해당 리스트에 들어있는 task들은 `python manage.py crontab add` 명령어를 통해 크론으로 등록시킬 수 있습니다.\n(첫 번째 인자, 두 번째 인자, 세 번째 인자)\n- 첫 번째 인자는 해당 task 를 실행할 주기를 등록하는 자리입니다. 예를 들어 \"* * * * *\" 은 매 분마다 라는 뜻입니다.\n- 두 번째 인자는 task 자체를 말합니다. 베이스 디렉토리에서 시작하며, 특정 모듈을 \".\"을 이용해서 지정해줍니다.\n- 세 번째 인자는 해당 task 를 실행할 때 뒤에 붙이고 싶은 명령어입니다. cron 자체가 윈도우에서는 동작하지 않기 때문에 대부분 unix 기반의 터미널 명령어를 추가해 줍니다. 여기서는 cronjob 에 오류가 났을 때 디버깅 하기 쉽도록 로그를 찍는 코드를 적어놓았습니다.\n\n\n\nref\n[https://pypi.org/project/django-crontab/](https://pypi.org/project/django-crontab/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneulhan%2Fcron-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneulhan%2Fcron-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneulhan%2Fcron-tutorial/lists"}