Skip to content

Instantly share code, notes, and snippets.

@piontas
Created August 25, 2014 11:32
Show Gist options
  • Save piontas/747d2b3c13e385fd912e to your computer and use it in GitHub Desktop.
Save piontas/747d2b3c13e385fd912e to your computer and use it in GitHub Desktop.
Django Haystack update index script
# -*- coding: utf-8 -*-
import logging
import subprocess
python_path = "/home/Environment/project/bin/python"
project_dir = "/home/production/project/"
log = "/var/log/update_index.log"
def update_index():
logging.basicConfig(filename=log, level=logging.INFO,
format='%(asctime)s %(levelname)s:%(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
logging.info('Updating indexes.')
ui = subprocess.Popen([python_path, project_dir+'manage.py',
'update_index'], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
ui.wait()
if not ui.returncode:
logging.info('Index successfully updated.')
else:
logging.error('Index update failed with return code %s'
% ui.returncode)
logging.error('Error info:')
logging.error('stdout: %s' % ui.communicate()[0])
logging.error('stderr: %s' % ui.communicate()[1])
if __name__ == '__main__':
update_index()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment