Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #47 from postatum/94850096_es_race_condition
Browse files Browse the repository at this point in the history
Refresh index cleanup
  • Loading branch information
jstoiko committed Jun 1, 2015
2 parents de21d44 + 59a1394 commit 72fce89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion nefertari/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def includeme(config):

def _bulk_body(body, refresh_index=None):
kwargs = {'body': body}
if refresh_index is not None:
refresh_provided = refresh_index is not None
refresh_enabled = ES.settings.asbool('enable_refresh_query')
if refresh_provided and refresh_enabled:
kwargs['refresh'] = refresh_index
return ES.api.bulk(**kwargs)

Expand Down
10 changes: 2 additions & 8 deletions nefertari/scripts/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ def __init__(self, argv, log):
'documents that are missing from index are indexed.'),
action='store_true',
default=False)
parser.add_argument(
'--refresh',
help='Refresh the index after performing the operation',
action='store_true',
default=False)

self.options = parser.parse_args()
if not self.options.config:
Expand Down Expand Up @@ -100,9 +95,8 @@ def run(self):
documents = to_dicts(query_set)

if self.options.force:
es.index(documents, refresh_index=self.options.refresh)
es.index(documents)
else:
es.index_missing_documents(
documents, refresh_index=self.options.refresh)
es.index_missing_documents(documents)

return 0
6 changes: 6 additions & 0 deletions nefertari/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ def __init__(self, context, request, _query_params={}, _json_params={}):
elif 'text/plain' in request.accept:
request.override_renderer = 'string'

if '_refresh_index' in self._query_params:
self.refresh_index = self._query_params.asbool(
'_refresh_index', pop=True)
else:
self.refresh_index = None

self._run_init_actions()

def _run_init_actions(self):
Expand Down

0 comments on commit 72fce89

Please sign in to comment.