Skip to content

Commit

Permalink
Merge pull request #1245 from noirbizarre/index-command-fixes
Browse files Browse the repository at this point in the history
Fixes on search index command
  • Loading branch information
noirbizarre committed Oct 26, 2017
2 parents a188759 + 4968135 commit 5d983e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Expand Up @@ -2,14 +2,14 @@

## Current (in progress)

- Nothing yet
- Fixes on the `search index command` [#1245](https://github.com/opendatateam/udata/pull/1245)

## 1.2.1 (2017-10-26)

- Introduce `udata search index` commmand to replace both deprecated `udata search init` and `udata search reindex` commands. They will be removed in udata 1.4. [#1233](https://github.com/opendatateam/udata/pull/1233)
- Rollback oauthlib from 2.0.5 to 2.0.2, pending a permanent solution [#1237](https://github.com/opendatateam/udata/pull/1237)
- Get cached linkchecker result before hitting API [#1235](https://github.com/opendatateam/udata/pull/1235)
- Cleanup resources checksum [migration] [#1239](https://github.com/opendatateam/udata/pull/1239)
- Cleanup resources checksum (migration) [#1239](https://github.com/opendatateam/udata/pull/1239)
- Show check results in resource modal [#1242](https://github.com/opendatateam/udata/pull/1242)
- Cache avatar rendering [#1243](https://github.com/opendatateam/udata/pull/1243)

Expand Down
17 changes: 11 additions & 6 deletions udata/search/commands.py
Expand Up @@ -120,7 +120,6 @@ def set_alias(index_name, delete=True):
es.indices.delete(index=index)
else:
es.indices.put_alias(index=index_name, name=es.index_name)
es.indices.refresh()


@contextmanager
Expand All @@ -133,17 +132,21 @@ def handle_error(index_name, keep=False):
# Handle keyboard interrupt
signal.signal(signal.SIGINT, signal.default_int_handler)
signal.signal(signal.SIGTERM, signal.default_int_handler)
has_error = False
try:
yield
except KeyboardInterrupt:
print('') # Proper warning message under the "^C" display
log.warning('Interrupted by signal')
has_error = True
except Exception as e:
log.error(e)
if not keep:
log.info('Removing index %s', index_name)
es.indices.delete(index=index_name)
sys.exit(-1)
has_error = True
if has_error:
if not keep:
log.info('Removing index %s', index_name)
es.indices.delete(index=index_name)
sys.exit(-1)


@m.option('-t', '--type', dest='doc_type', required=True,
Expand Down Expand Up @@ -223,5 +226,7 @@ def index(models=None, name=None, force=False, keep=False):
'doc_type': adapter.doc_type()
})

enable_refresh(index_name)
enable_refresh(index_name)
# At this step, we don't want error handler to delete the index
# in case of error
set_alias(index_name, delete=not keep)

0 comments on commit 5d983e9

Please sign in to comment.