Skip to content

Commit

Permalink
add searchvector schedule config
Browse files Browse the repository at this point in the history
  • Loading branch information
oleggator committed Oct 1, 2019
1 parent 27d35f4 commit ace2b6a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
8 changes: 8 additions & 0 deletions contrib/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ NEW_RELIC_ENVIRONMENT=development
NEW_RELIC_LICENSE_KEY=

INBOX_PASSWORD=

SCHEDULE_SEARCHVECTOR=True
SCHEDULE_SEARCHVECTOR_CRON_MINUTE=0
SCHEDULE_SEARCHVECTOR_CRON_HOUR=2
SCHEDULE_SEARCHVECTOR_CRON_DAY_OF_WEEK=*
SCHEDULE_SEARCHVECTOR_CRON_DAY_OF_MONTH=*/2
SCHEDULE_SEARCHVECTOR_CRON_MONTH_OF_YEAR=*

16 changes: 12 additions & 4 deletions jarbas/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from celery import Celery
from celery.schedules import crontab

from django.conf import settings

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jarbas.settings')

Expand All @@ -20,7 +21,14 @@ def searchvector():
management.call_command('searchvector')
print('Searchvector is done')

sender.add_periodic_task(
crontab(minute='0', hour='2', day_of_month='*/2'),
searchvector.s(),
)
if settings.SCHEDULE_SEARCHVECTOR:
sender.add_periodic_task(
crontab(
minute=settings.SCHEDULE_SEARCHVECTOR_CRON_MINUTE,
hour=settings.SCHEDULE_SEARCHVECTOR_CRON_HOUR,
day_of_week=settings.SCHEDULE_SEARCHVECTOR_CRON_DAY_OF_WEEK,
day_of_month=settings.SCHEDULE_SEARCHVECTOR_CRON_DAY_OF_MONTH,
month_of_year=settings.SCHEDULE_SEARCHVECTOR_CRON_MONTH_OF_YEAR,
),
searchvector.s(),
)
9 changes: 9 additions & 0 deletions jarbas/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,12 @@
# Set home

HOMES_REDIRECTS_TO = '/dashboard/chamber_of_deputies/reimbursement/'

# Searchvector schedule

SCHEDULE_SEARCHVECTOR = config('SCHEDULE_SEARCHVECTOR', default=False, cast=bool)
SCHEDULE_SEARCHVECTOR_CRON_MINUTE = config('SCHEDULE_SEARCHVECTOR_CRON_MINUTE', default='0')
SCHEDULE_SEARCHVECTOR_CRON_HOUR = config('SCHEDULE_SEARCHVECTOR_CRON_HOUR', default='2')
SCHEDULE_SEARCHVECTOR_CRON_DAY_OF_WEEK = config('SCHEDULE_SEARCHVECTOR_CRON_DAY_OF_WEEK', default='*')
SCHEDULE_SEARCHVECTOR_CRON_DAY_OF_MONTH = config('SCHEDULE_SEARCHVECTOR_CRON_DAY_OF_MONTH', default='*/2')
SCHEDULE_SEARCHVECTOR_CRON_MONTH_OF_YEAR = config('SCHEDULE_SEARCHVECTOR_CRON_MONTH_OF_YEAR', default='*')

0 comments on commit ace2b6a

Please sign in to comment.