Skip to content

Commit

Permalink
Proof of concept for xloader site url
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalsh committed Nov 18, 2024
1 parent 6b68959 commit 43203b8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
23 changes: 12 additions & 11 deletions ckanext/xloader/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,18 @@ def xloader_submit(context, data_dict):
qualified=True
)
data = {
'api_key': utils.get_xloader_user_apitoken(),
'job_type': 'xloader_to_datastore',
'result_url': callback_url,
'metadata': {
'ignore_hash': data_dict.get('ignore_hash', False),
'ckan_url': config['ckan.site_url'],
'resource_id': res_id,
'set_url_type': data_dict.get('set_url_type', False),
'task_created': task['last_updated'],
'original_url': resource_dict.get('url'),
}
"api_key": utils.get_xloader_user_apitoken(),
"job_type": "xloader_to_datastore",
"result_url": callback_url,
"metadata": {
"ignore_hash": data_dict.get("ignore_hash", False),
"ckan_url": config.get("ckanext.xloader.site_url")
or config["ckan.site_url"],
"resource_id": res_id,
"set_url_type": data_dict.get("set_url_type", False),
"task_created": task["last_updated"],
"original_url": resource_dict.get("url"),
},
}
if custom_queue != rq_jobs.DEFAULT_QUEUE_NAME:
# Don't automatically retry if it's a custom run
Expand Down
11 changes: 5 additions & 6 deletions ckanext/xloader/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,11 @@ def _submit_resource(self, resource, user, indent=0, sync=False, queue=None):
'ignore_hash': True,
}
if sync:
data_dict['ckan_url'] = tk.config.get('ckan.site_url')
input_dict = {
'metadata': data_dict,
'api_key': 'TODO'
}
logger = logging.getLogger('ckanext.xloader.cli')
data_dict["ckan_url"] = tk.config.get(
"ckanext.xloader.site_url"
) or tk.config.get("ckan.site_url")
input_dict = {"metadata": data_dict, "api_key": "TODO"}
logger = logging.getLogger("ckanext.xloader.cli")
xloader_data_into_datastore_(input_dict, None, logger)
else:
if queue:
Expand Down
8 changes: 6 additions & 2 deletions ckanext/xloader/config_declaration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ version: 1
groups:
- annotation: ckanext-xloader settings
options:
- key: ckanext.xloader.site_url
default:
description: |
Provide an alternate site URL for the xloader_submit action.
This is useful, for example, when the site is running within a docker network.
required: false
- key: ckanext.xloader.jobs_db.uri
default: sqlite:////tmp/xloader_jobs.db
description: |
Expand Down Expand Up @@ -152,5 +158,3 @@ groups:
they will also display "complete", "active", "inactive", and "unknown".
type: bool
required: false


12 changes: 5 additions & 7 deletions ckanext/xloader/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ def configure(self, config_):
else:
self.ignore_hash = False

for config_option in ("ckan.site_url",):
if not config_.get(config_option):
raise Exception(
"Config option `{0}` must be set to use ckanext-xloader.".format(
config_option
)
)
site_url_configs = ("ckan.site_url", "ckanext.xloader.site_url")
if not any(site_url_configs):
raise Exception(
f"One of config options {site_url_configs} must be set to use ckanext-xloader."
)

# IDomainObjectModification

Expand Down
23 changes: 12 additions & 11 deletions ckanext/xloader/tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ def data(create_with_upload, apikey):
"api.action", ver=3, logic_function="xloader_hook", qualified=True
)
return {
'api_key': apikey,
'job_type': 'xloader_to_datastore',
'result_url': callback_url,
'metadata': {
'ignore_hash': True,
'ckan_url': toolkit.config.get('ckan.site_url'),
'resource_id': resource["id"],
'set_url_type': False,
'task_created': datetime.utcnow().isoformat(),
'original_url': resource["url"],
}
"api_key": apikey,
"job_type": "xloader_to_datastore",
"result_url": callback_url,
"metadata": {
"ignore_hash": True,
"ckan_url": toolkit.config.get("ckanext.xloader.site_url")
or toolkit.config.get("ckan.site_url"),
"resource_id": resource["id"],
"set_url_type": False,
"task_created": datetime.utcnow().isoformat(),
"original_url": resource["url"],
},
}


Expand Down

0 comments on commit 43203b8

Please sign in to comment.