Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Setup django-crontab #5410

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions fec/fec/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
'legal',
'uaa_client',
'extend_admin',
'django_crontab',
)

MIDDLEWARE = (
Expand Down Expand Up @@ -211,6 +212,17 @@
'default': dj_database_url.config()
}

# cfdm_cms_test database properties required when scraping via crontab
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': 'cfdm_cms_test',
# 'USER': '<database username>',
# 'PASSWORD': '<database password>',
# 'HOST': 'localhost',
# 'PORT': '5432',
# }
# }

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
Expand Down Expand Up @@ -340,4 +352,11 @@
},
}

CRONTAB_COMMAND_SUFFIX = '2>&1'

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
CRONJOBS = [
#transition is taking the place of indexing, I did every Tuesday and hour apart as a sample
('0 1 * * TUE', 'django.core.management.call_command', ['scrape_cms_pages'], {}, ('> ' + os.path.join(BASE_DIR,'cms_scrape.log'))),
('0 0 * * TUE', 'django.core.management.call_command', ['scrape_transition_pages'], {}, ('> ' + os.path.join(BASE_DIR,'transition.log'))),
]
13 changes: 13 additions & 0 deletions fec/search/schedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3
import os
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
logger = logging.getLogger(__name__)

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)


def run_job():
logger.info('Hello, This is my first cron job...' + ' 2>&1 ')
# logger.info('Hello, This is my first cron job...' + os.path.join(BASE_DIR,'scheduler.log' + ' 2>&1 ')
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ pytest-django==3.10.0
pytest-cov==2.11.1
pytest-flake8==1.0.7
setuptools==65.1.1 # Pinned to fix the deploy errors caused by the latest setuptool version 65.3.0

#scheduler
django-crontab==0.7.1