ckanext-xloader 2.1.0__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ckanext_xloader-2.1.0/ckanext_xloader.egg-info → ckanext_xloader-2.2.0}/PKG-INFO +3 -2
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/config_declaration.yaml +19 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/helpers.py +1 -1
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/job_exceptions.py +5 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/jobs.py +102 -45
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/loader.py +314 -242
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/schema.py +0 -2
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/tests/test_jobs.py +84 -1
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/tests/test_loader.py +22 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/tests/test_utils.py +2 -2
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/utils.py +45 -50
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0/ckanext_xloader.egg-info}/PKG-INFO +3 -2
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/pyproject.toml +1 -1
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/CHANGELOG +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/LICENSE +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/MANIFEST.in +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/README.md +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/__init__.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/__init__.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/action.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/auth.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/cli.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/command.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/db.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/interfaces.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/parser.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/plugin.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/templates/datastore/snippets/dictionary_form.html +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/templates/package/resource_edit_base.html +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/templates/package/resource_read.html +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/templates/package/snippets/resource_info.html +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/templates/package/snippets/resource_item.html +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/templates/package/snippets/resources.html +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/templates/xloader/confirm_datastore_delete.html +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/templates/xloader/resource_data.html +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/tests/__init__.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/tests/ckan_setup.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/tests/fixtures.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/tests/test_action.py +1 -1
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/tests/test_parser.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/tests/test_plugin.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/views.py +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/webassets/css/xloader.css +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext/xloader/webassets/webassets.yml +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext_xloader.egg-info/SOURCES.txt +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext_xloader.egg-info/dependency_links.txt +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext_xloader.egg-info/entry_points.txt +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext_xloader.egg-info/requires.txt +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/ckanext_xloader.egg-info/top_level.txt +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/dev-requirements.txt +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/requirements.txt +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/setup.cfg +0 -0
- {ckanext_xloader-2.1.0 → ckanext_xloader-2.2.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: ckanext-xloader
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Express Loader - quickly load data into CKAN DataStore
|
|
5
5
|
Author: David Read (davidread), Patricio Del Boca (pdelboca)
|
|
6
6
|
Author-email: ThrawnCA <carl.antuar@smartservice.qld.gov.au>, "Jesse Vickery (JVickery-TBS)" <jesse.vickery@tbs-sct.gc.ca>, "Adrià Mercader (amercader)" <amercadero@gmail.com>, "Brett Jones (kowh-ai)" <datashades@linkdigital.com.au>, "William Dutton (duttonw)" <william.dutton@qld.gov.au>
|
|
@@ -20,6 +20,7 @@ License-File: LICENSE
|
|
|
20
20
|
Requires-Dist: typing_extensions
|
|
21
21
|
Provides-Extra: test
|
|
22
22
|
Requires-Dist: pytest-factoryboy; extra == "test"
|
|
23
|
+
Dynamic: license-file
|
|
23
24
|
|
|
24
25
|
# XLoader - ckanext-xloader
|
|
25
26
|
|
|
@@ -187,3 +187,22 @@ groups:
|
|
|
187
187
|
they will also display "complete", "active", "inactive", and "unknown".
|
|
188
188
|
type: bool
|
|
189
189
|
required: false
|
|
190
|
+
- key: ckanext.xloader.search_update_chunks
|
|
191
|
+
default: 100000
|
|
192
|
+
example: 1000
|
|
193
|
+
description: |
|
|
194
|
+
The number of rows to process in each batch when populating the full-text
|
|
195
|
+
search index. Chunked processing prevents database timeouts and memory
|
|
196
|
+
exhaustion when indexing very large datasets (4GB+ files with millions of rows).
|
|
197
|
+
Smaller values reduce memory usage but increase processing time. Larger values
|
|
198
|
+
improve performance but may cause timeouts on very large tables.
|
|
199
|
+
type: int
|
|
200
|
+
required: false
|
|
201
|
+
- key: ckanext.xloader.max_retries
|
|
202
|
+
default: 1
|
|
203
|
+
example: 3
|
|
204
|
+
description: |
|
|
205
|
+
Maximum number of retry attempts for failed jobs due to temporary errors
|
|
206
|
+
like database deadlocks or network timeouts. Set to 0 to disable retries.
|
|
207
|
+
type: int
|
|
208
|
+
required: false
|
|
@@ -40,7 +40,7 @@ def is_resource_supported_by_xloader(res_dict, check_access=True):
|
|
|
40
40
|
try:
|
|
41
41
|
is_supported_url_type = url_type not in toolkit.h.datastore_rw_resource_url_types()
|
|
42
42
|
except AttributeError:
|
|
43
|
-
is_supported_url_type = (url_type
|
|
43
|
+
is_supported_url_type = (url_type in ['upload', 'None'])
|
|
44
44
|
else:
|
|
45
45
|
is_supported_url_type = True
|
|
46
46
|
return (is_supported_format or is_datastore_active) and user_has_access and is_supported_url_type
|
|
@@ -18,11 +18,10 @@ from rq import get_current_job
|
|
|
18
18
|
from rq.timeouts import JobTimeoutException
|
|
19
19
|
import sqlalchemy as sa
|
|
20
20
|
|
|
21
|
-
from ckan import model
|
|
22
21
|
from ckan.plugins.toolkit import get_action, asbool, enqueue_job, ObjectNotFound, config, h
|
|
23
22
|
|
|
24
23
|
from . import db, loader
|
|
25
|
-
from .job_exceptions import JobError, HTTPError, DataTooBigError, FileCouldNotBeLoadedError
|
|
24
|
+
from .job_exceptions import JobError, HTTPError, DataTooBigError, FileCouldNotBeLoadedError, LoaderError, XLoaderTimeoutError
|
|
26
25
|
from .utils import datastore_resource_exists, set_resource_metadata, modify_input_url
|
|
27
26
|
|
|
28
27
|
|
|
@@ -41,11 +40,13 @@ MAX_EXCERPT_LINES = int(config.get('ckanext.xloader.max_excerpt_lines') or 0)
|
|
|
41
40
|
CHUNK_SIZE = 16 * 1024 # 16kb
|
|
42
41
|
DOWNLOAD_TIMEOUT = 30
|
|
43
42
|
|
|
44
|
-
MAX_RETRIES = 1
|
|
43
|
+
MAX_RETRIES = int(config.get('ckanext.xloader.max_retries', 1))
|
|
45
44
|
RETRYABLE_ERRORS = (
|
|
46
45
|
errors.DeadlockDetected,
|
|
47
46
|
errors.LockNotAvailable,
|
|
48
47
|
errors.ObjectInUse,
|
|
48
|
+
HTTPError,
|
|
49
|
+
XLoaderTimeoutError
|
|
49
50
|
)
|
|
50
51
|
# Retries can only occur in cases where the datastore entry exists,
|
|
51
52
|
# so use the standard timeout
|
|
@@ -53,6 +54,38 @@ RETRIED_JOB_TIMEOUT = config.get('ckanext.xloader.job_timeout', '3600')
|
|
|
53
54
|
APITOKEN_HEADER_NAME = config.get('apitoken_header_name', 'Authorization')
|
|
54
55
|
|
|
55
56
|
|
|
57
|
+
def is_retryable_error(error):
|
|
58
|
+
"""
|
|
59
|
+
Determine if an error should trigger a retry attempt.
|
|
60
|
+
|
|
61
|
+
Checks if the error is a temporary/transient condition that might
|
|
62
|
+
succeed on retry. Returns True for retryable HTTP status codes and
|
|
63
|
+
other temporary errors.
|
|
64
|
+
|
|
65
|
+
Retryable HTTP status codes:
|
|
66
|
+
- 408 Request Timeout
|
|
67
|
+
- 429 Too Many Requests
|
|
68
|
+
- 500 Internal Server Error
|
|
69
|
+
- 502 Bad Gateway
|
|
70
|
+
- 503 Service Unavailable
|
|
71
|
+
- 504 Gateway Timeout
|
|
72
|
+
- 507 Insufficient Storage
|
|
73
|
+
- 522 Connection Timed Out (Cloudflare)
|
|
74
|
+
- 524 A Timeout Occurred (Cloudflare)
|
|
75
|
+
|
|
76
|
+
:param error: Exception object to check
|
|
77
|
+
:type error: Exception
|
|
78
|
+
:return: True if error should be retried, False otherwise
|
|
79
|
+
:rtype: bool
|
|
80
|
+
"""
|
|
81
|
+
if isinstance(error, HTTPError):
|
|
82
|
+
retryable_status_codes = {408, 429, 500, 502, 503, 504, 507, 522, 524}
|
|
83
|
+
return error.status_code in retryable_status_codes
|
|
84
|
+
else:
|
|
85
|
+
return True
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
|
|
56
89
|
# input = {
|
|
57
90
|
# 'api_key': user['apikey'],
|
|
58
91
|
# 'job_type': 'xloader_to_datastore',
|
|
@@ -112,36 +145,12 @@ def xloader_data_into_datastore(input):
|
|
|
112
145
|
job_dict['error'] = str(e)
|
|
113
146
|
log.error('xloader error: job_id %s already exists', job_id)
|
|
114
147
|
errored = True
|
|
115
|
-
except JobError as e:
|
|
116
|
-
db.mark_job_as_errored(job_id, str(e))
|
|
117
|
-
job_dict['status'] = 'error'
|
|
118
|
-
job_dict['error'] = str(e)
|
|
119
|
-
log.error('xloader error: %s, %s', e, traceback.format_exc())
|
|
120
|
-
errored = True
|
|
121
148
|
except Exception as e:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
logger.info("Job failed due to temporary error [%s], retrying", e)
|
|
128
|
-
job_dict['status'] = 'pending'
|
|
129
|
-
job_dict['metadata']['tries'] = tries
|
|
130
|
-
enqueue_job(
|
|
131
|
-
xloader_data_into_datastore,
|
|
132
|
-
[input],
|
|
133
|
-
title="retry xloader_data_into_datastore: resource: {} attempt {}".format(
|
|
134
|
-
job_dict['metadata']['resource_id'], tries),
|
|
135
|
-
rq_kwargs=dict(timeout=RETRIED_JOB_TIMEOUT)
|
|
136
|
-
)
|
|
137
|
-
return None
|
|
138
|
-
|
|
139
|
-
db.mark_job_as_errored(
|
|
140
|
-
job_id, traceback.format_tb(sys.exc_info()[2])[-1] + repr(e))
|
|
141
|
-
job_dict['status'] = 'error'
|
|
142
|
-
job_dict['error'] = str(e)
|
|
143
|
-
log.error('xloader error: %s, %s', e, traceback.format_exc())
|
|
144
|
-
errored = True
|
|
149
|
+
error_state = {'errored': errored}
|
|
150
|
+
retry = handle_retryable_error(e, input, job_id, job_dict, logger, error_state)
|
|
151
|
+
if retry:
|
|
152
|
+
return None
|
|
153
|
+
errored = error_state['errored']
|
|
145
154
|
finally:
|
|
146
155
|
# job_dict is defined in xloader_hook's docstring
|
|
147
156
|
is_saved_ok = callback_xloader_hook(result_url=input['result_url'],
|
|
@@ -151,6 +160,54 @@ def xloader_data_into_datastore(input):
|
|
|
151
160
|
return 'error' if errored else None
|
|
152
161
|
|
|
153
162
|
|
|
163
|
+
def handle_retryable_error(e, input, job_id, job_dict, logger, error_state):
|
|
164
|
+
"""
|
|
165
|
+
Handle retryable errors by attempting to retry the job or marking it as failed.
|
|
166
|
+
|
|
167
|
+
Checks if the error is retryable (database deadlocks, HTTP timeouts, etc.) and
|
|
168
|
+
within the retry limit. If so, enqueues a new job attempt. Otherwise, marks
|
|
169
|
+
the job as errored.
|
|
170
|
+
|
|
171
|
+
:param e: The exception that occurred
|
|
172
|
+
:type e: Exception
|
|
173
|
+
:param input: Job input data containing metadata and API key
|
|
174
|
+
:type input: dict
|
|
175
|
+
:param job_id: Unique identifier for the current job
|
|
176
|
+
:type job_id: str
|
|
177
|
+
:param job_dict: Job status dictionary with metadata and status
|
|
178
|
+
:type job_dict: dict
|
|
179
|
+
:param logger: Logger instance for the current job
|
|
180
|
+
:type logger: logging.Logger
|
|
181
|
+
:param error_state: Mutable dict to track error state {'errored': bool}
|
|
182
|
+
:type error_state: dict
|
|
183
|
+
|
|
184
|
+
:returns: True if job was retried, None otherwise
|
|
185
|
+
:rtype: bool or None
|
|
186
|
+
"""
|
|
187
|
+
if isinstance(e, RETRYABLE_ERRORS) and is_retryable_error(e):
|
|
188
|
+
tries = job_dict['metadata'].get('tries', 0)
|
|
189
|
+
if tries < MAX_RETRIES:
|
|
190
|
+
tries = tries + 1
|
|
191
|
+
log.info("Job %s failed due to temporary error [%s], retrying", job_id, e)
|
|
192
|
+
logger.info("Job failed due to temporary error [%s], retrying", e)
|
|
193
|
+
job_dict['status'] = 'pending'
|
|
194
|
+
job_dict['metadata']['tries'] = tries
|
|
195
|
+
enqueue_job(
|
|
196
|
+
xloader_data_into_datastore,
|
|
197
|
+
[input],
|
|
198
|
+
title="retry xloader_data_into_datastore: resource: {} attempt {}".format(
|
|
199
|
+
job_dict['metadata']['resource_id'], tries),
|
|
200
|
+
rq_kwargs=dict(timeout=RETRIED_JOB_TIMEOUT)
|
|
201
|
+
)
|
|
202
|
+
return True
|
|
203
|
+
db.mark_job_as_errored(
|
|
204
|
+
job_id, traceback.format_tb(sys.exc_info()[2])[-1] + repr(e))
|
|
205
|
+
job_dict['status'] = 'error'
|
|
206
|
+
job_dict['error'] = str(e)
|
|
207
|
+
log.error('xloader error: %s, %s', e, traceback.format_exc())
|
|
208
|
+
error_state['errored'] = True
|
|
209
|
+
|
|
210
|
+
|
|
154
211
|
def xloader_data_into_datastore_(input, job_dict, logger):
|
|
155
212
|
'''This function:
|
|
156
213
|
* downloads the resource (metadata) from CKAN
|
|
@@ -200,11 +257,12 @@ def xloader_data_into_datastore_(input, job_dict, logger):
|
|
|
200
257
|
logger.info('File hash: %s', file_hash)
|
|
201
258
|
resource['hash'] = file_hash
|
|
202
259
|
|
|
203
|
-
def direct_load():
|
|
260
|
+
def direct_load(allow_type_guessing=False):
|
|
204
261
|
fields = loader.load_csv(
|
|
205
262
|
tmp_file.name,
|
|
206
263
|
resource_id=resource['id'],
|
|
207
264
|
mimetype=resource.get('format'),
|
|
265
|
+
allow_type_guessing=allow_type_guessing,
|
|
208
266
|
logger=logger)
|
|
209
267
|
loader.calculate_record_count(
|
|
210
268
|
resource_id=resource['id'], logger=logger)
|
|
@@ -260,24 +318,24 @@ def xloader_data_into_datastore_(input, job_dict, logger):
|
|
|
260
318
|
direct_load()
|
|
261
319
|
else:
|
|
262
320
|
try:
|
|
263
|
-
direct_load()
|
|
264
|
-
except JobError as e:
|
|
321
|
+
direct_load(allow_type_guessing=True)
|
|
322
|
+
except (JobError, LoaderError) as e:
|
|
265
323
|
logger.warning('Load using COPY failed: %s', e)
|
|
266
324
|
logger.info('Trying again with tabulator')
|
|
267
325
|
tabulator_load()
|
|
268
326
|
except JobTimeoutException:
|
|
269
|
-
try:
|
|
270
|
-
tmp_file.close()
|
|
271
|
-
except FileNotFoundError:
|
|
272
|
-
pass
|
|
273
327
|
logger.warning('Job timed out after %ss', RETRIED_JOB_TIMEOUT)
|
|
274
328
|
raise JobError('Job timed out after {}s'.format(RETRIED_JOB_TIMEOUT))
|
|
275
329
|
except FileCouldNotBeLoadedError as e:
|
|
276
330
|
logger.warning('Loading excerpt for this format not supported.')
|
|
277
331
|
logger.error('Loading file raised an error: %s', e)
|
|
278
332
|
raise JobError('Loading file raised an error: {}'.format(e))
|
|
279
|
-
|
|
280
|
-
|
|
333
|
+
finally:
|
|
334
|
+
try:
|
|
335
|
+
tmp_file.close()
|
|
336
|
+
os.remove(tmp_file.name)
|
|
337
|
+
except FileNotFoundError:
|
|
338
|
+
pass
|
|
281
339
|
|
|
282
340
|
logger.info('Express Load completed')
|
|
283
341
|
|
|
@@ -380,8 +438,8 @@ def _download_resource_data(resource, data, api_key, logger):
|
|
|
380
438
|
request_url=url, response=error)
|
|
381
439
|
except requests.exceptions.Timeout:
|
|
382
440
|
logger.warning('URL time out after %ss', DOWNLOAD_TIMEOUT)
|
|
383
|
-
raise
|
|
384
|
-
|
|
441
|
+
raise XLoaderTimeoutError('Connection timed out after {}s'.format(
|
|
442
|
+
DOWNLOAD_TIMEOUT))
|
|
385
443
|
except requests.exceptions.RequestException as e:
|
|
386
444
|
tmp_file.close()
|
|
387
445
|
try:
|
|
@@ -467,7 +525,7 @@ def callback_xloader_hook(result_url, api_key, job_dict):
|
|
|
467
525
|
|
|
468
526
|
try:
|
|
469
527
|
result = requests.post(
|
|
470
|
-
modify_input_url(result_url),
|
|
528
|
+
modify_input_url(result_url), # modify with local config
|
|
471
529
|
data=json.dumps(job_dict, cls=DatetimeJsonEncoder),
|
|
472
530
|
verify=SSL_VERIFY,
|
|
473
531
|
headers=headers)
|
|
@@ -514,7 +572,6 @@ def _get_user_from_key(api_key_or_token):
|
|
|
514
572
|
return get_user_from_token(api_key_or_token)
|
|
515
573
|
|
|
516
574
|
|
|
517
|
-
|
|
518
575
|
def get_resource_and_dataset(resource_id, api_key):
|
|
519
576
|
"""
|
|
520
577
|
Gets available information about the resource and its dataset from CKAN
|