Skip to content

Commit

Permalink
Fix async updating of metadata search index
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-saeon committed Jan 24, 2019
1 parent 4318d24 commit 0531c24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions ckanext/metadata/elastic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def metadata_record_index_update(original_action, context, data_dict):
"""
Add/update/delete a metadata record in a search index.
Note: this is done asynchronously.
:param id: the id or name of the metadata record
:type id: string
"""
Expand Down Expand Up @@ -102,8 +104,8 @@ def metadata_record_index_update(original_action, context, data_dict):
.all()
infrastructure_titles = [title for (title,) in infrastructure_titles]

client.push_record(index_name, record_id, metadata_record.extras['metadata_json'],
organization_title, collection_title, infrastructure_titles)
client.put_record(index_name, record_id, metadata_record.extras['metadata_json'],
organization_title, collection_title, infrastructure_titles)


@tk.chained_action
Expand Down
6 changes: 3 additions & 3 deletions ckanext/metadata/elastic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def _search_agent_url():
return config.get('ckan.metadata.elastic.search_agent_url')


@app.task
def _call_agent_async(url, **kwargs):
_call_agent.delay(url, **kwargs)


@app.task
def _call_agent(url, *outputs, **kwargs):
"""
Post a request to the Elastic search agent.
Expand Down Expand Up @@ -77,7 +77,7 @@ def get_index_mapping(index_name):


# asynchronous
def push_record(index_name, record_id, metadata_json, organization, collection, infrastructures):
def put_record(index_name, record_id, metadata_json, organization, collection, infrastructures):
url = _search_agent_url() + '/add'
_call_agent_async(url, index=index_name, record_id=record_id, metadata_json=metadata_json,
organization=organization, collection=collection, infrastructures=infrastructures)
Expand All @@ -86,4 +86,4 @@ def push_record(index_name, record_id, metadata_json, organization, collection,
# asynchronous
def delete_record(index_name, record_id):
url = _search_agent_url() + '/delete'
_call_agent_async(url, index=index_name, record_id=record_id)
_call_agent_async(url, index=index_name, record_id=record_id, force=True)

0 comments on commit 0531c24

Please sign in to comment.