Skip to content

Commit 1bbd643

Browse files
committed
squash(pr): 200;
- Squashed version of ckan#200.
1 parent 27b4c03 commit 1bbd643

File tree

7 files changed

+74
-14
lines changed

7 files changed

+74
-14
lines changed

CHANGELOG

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
1.1.3 2024-12-09
2+
================
3+
4+
Feat:
5+
* Adds support for ckanext-validation. Config `ckanext.xloader.validation.requires_successful_report` controls whether a resource requires a successful validation report to be XLoadered. By default, a resource would also require a Validation Schema, which can be turned off with `ckanext.xloader.validation.enforce_schema`.
6+
7+
8+
**Full Changelog**: https://github.com/ckan/ckanext-xloader/compare/1.1.2...1.1.3
9+
110
1.1.2 2024-10-25
211
================
312

@@ -21,7 +30,7 @@ Fix:
2130
1.1.0 2024-10-16
2231
================
2332

24-
Fixes:
33+
Fixes:
2534
* feat: Add pypi cicd publish via github action via environment controls by @duttonw in https://github.com/ckan/ckanext-xloader/pull/228
2635

2736

@@ -32,7 +41,7 @@ Fixes:
3241
================
3342

3443

35-
Fixes:
44+
Fixes:
3645

3746
* add README note about running on separate server, #191 by @ThrawnCA in https://github.com/ckan/ckanext-xloader/pull/192
3847
* Use IDomainObjectModification Implementation by @JVickery-TBS in https://github.com/ckan/ckanext-xloader/pull/198

README.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Compatibility with core CKAN versions:
115115
| CKAN version | Compatibility |
116116
| -------------- | -------------------------------------------------------------------------------------------------------------- |
117117
| 2.7 | no longer supported (last supported version: 0.12.2) |
118-
| 2.8 | no longer supported (last supported version: 0.12.2) |
118+
| 2.8 | no longer supported (last supported version: 0.12.2) |
119119
| 2.9 | yes (Python3) (last supported version for Python 2.7: 0.12.2)), Must: `pip install "setuptools>=44.1.0,<71"` |
120120
| 2.10 | yes |
121121
| 2.11 | yes |
@@ -189,7 +189,7 @@ expect European (day-first) dates, you could add to `postgresql.conf`:
189189

190190
datestyle=ISO,DMY
191191

192-
All configurations below are defined in the
192+
All configurations below are defined in the
193193
[config_declaration.yaml](ckanext/xloader/config_declaration.yaml) file.
194194

195195

@@ -409,6 +409,34 @@ Controls whether or not the status badges display all of the statuses. By defaul
409409
the badges will display "pending", "running", and "error". With debug_badges enabled,
410410
they will also display "complete", "active", "inactive", and "unknown".
411411

412+
#### ckanext.xloader.validation.requires_successful_report
413+
414+
Supports: __ckanext-validation__
415+
416+
Example:
417+
418+
```
419+
ckanext.xloader.validation.requires_successful_report = True
420+
```
421+
422+
Default value: `False`
423+
424+
Controls whether or not a resource requires a successful validation report from the ckanext-validation plugin in order to be XLoadered.
425+
426+
#### ckanext.xloader.validation.enforce_schema
427+
428+
Supports: __ckanext-validation__
429+
430+
Example:
431+
432+
```
433+
ckanext.xloader.validation.enforce_schema = False
434+
```
435+
436+
Default value: `True`
437+
438+
Controls whether or not a resource requires a Validation Schema to be present from the ckanext-validation plugin to be XLoadered.
439+
412440
## Developer installation
413441

414442
To install XLoader for development, activate your CKAN virtualenv and in

ckanext/xloader/action.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ def xloader_submit(context, data_dict):
5353
if errors:
5454
raise p.toolkit.ValidationError(errors)
5555

56+
p.toolkit.check_access('xloader_submit', context, data_dict)
57+
58+
# If sync is set to True, the xloader callback will be executed right
59+
# away, instead of a job being enqueued. It will also delete any existing jobs
60+
# for the given resource. This is only controlled by sysadmins or the system.
61+
sync = data_dict.pop('sync', False)
62+
5663
res_id = data_dict['resource_id']
5764
try:
5865
resource_dict = p.toolkit.get_action('resource_show')(context, {
@@ -166,15 +173,20 @@ def xloader_submit(context, data_dict):
166173
job = enqueue_job(
167174
jobs.xloader_data_into_datastore, [data], queue=custom_queue,
168175
title="xloader_submit: package: {} resource: {}".format(resource_dict.get('package_id'), res_id),
169-
rq_kwargs=dict(timeout=timeout)
176+
rq_kwargs=dict(timeout=timeout, at_front=sync)
170177
)
171178
except Exception:
172-
log.exception('Unable to enqueued xloader res_id=%s', res_id)
179+
if sync:
180+
log.exception('Unable to xloader res_id=%s', res_id)
181+
else:
182+
log.exception('Unable to enqueue xloader res_id=%s', res_id)
173183
return False
174184
log.debug('Enqueued xloader job=%s res_id=%s', job.id, res_id)
175-
176185
value = json.dumps({'job_id': job.id})
177186

187+
if sync:
188+
log.debug('Pushed xloader sync mode job=%s res_id=%s to front of queue', job.id, res_id)
189+
178190
task['value'] = value
179191
task['state'] = 'pending'
180192
task['last_updated'] = str(datetime.datetime.utcnow())

ckanext/xloader/config_declaration.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ groups:
141141
example: False
142142
description: |
143143
Resources are expected to have a Validation Schema, or use the default ones if not.
144+
144145
If this option is set to `False`, Resources that do not have
145146
a Validation Schema will be treated like they do not require Validation.
147+
146148
See https://github.com/frictionlessdata/ckanext-validation?tab=readme-ov-file#data-schema
147149
for more details.
148150
- key: ckanext.xloader.clean_datastore_tables

ckanext/xloader/plugin.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def before_show(self, resource_dict):
183183
def after_update(self, context, resource_dict):
184184
self.after_resource_update(context, resource_dict)
185185

186-
def _submit_to_xloader(self, resource_dict):
186+
def _submit_to_xloader(self, resource_dict, sync=False):
187187
context = {"ignore_auth": True, "defer_commit": True}
188188
resource_format = resource_dict.get("format")
189189
if not XLoaderFormats.is_it_an_xloader_format(resource_format):
@@ -203,14 +203,20 @@ def _submit_to_xloader(self, resource_dict):
203203
return
204204

205205
try:
206-
log.debug(
207-
"Submitting resource %s to be xloadered", resource_dict["id"]
208-
)
206+
if sync:
207+
log.debug(
208+
"xloadering resource %s in sync mode", resource_dict["id"]
209+
)
210+
else:
211+
log.debug(
212+
"Submitting resource %s to be xloadered", resource_dict["id"]
213+
)
209214
toolkit.get_action("xloader_submit")(
210215
context,
211216
{
212217
"resource_id": resource_dict["id"],
213218
"ignore_hash": self.ignore_hash,
219+
"sync": sync,
214220
},
215221
)
216222
except toolkit.ValidationError as e:

ckanext/xloader/schema.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
boolean_validator = get_validator('boolean_validator')
1717
int_validator = get_validator('int_validator')
1818
OneOf = get_validator('OneOf')
19+
ignore_not_sysadmin = get_validator('ignore_not_sysadmin')
1920

2021
if p.toolkit.check_ckan_version('2.9'):
2122
unicode_safe = get_validator('unicode_safe')
@@ -29,6 +30,7 @@ def xloader_submit_schema():
2930
'id': [ignore_missing],
3031
'set_url_type': [ignore_missing, boolean_validator],
3132
'ignore_hash': [ignore_missing, boolean_validator],
33+
'sync': [ignore_missing, boolean_validator, ignore_not_sysadmin],
3234
'__junk': [empty],
3335
'__before': [dsschema.rename('id', 'resource_id')]
3436
}

ckanext/xloader/utils.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import datetime
5+
from rq import get_current_job
56

67
from six import text_type as str, binary_type
78

@@ -33,8 +34,6 @@
3334
"application/vnd.oasis.opendocument.spreadsheet",
3435
]
3536

36-
from .job_exceptions import JobError
37-
3837

3938
class XLoaderFormats(object):
4039
formats = None
@@ -61,8 +60,10 @@ def awaiting_validation(res_dict):
6160
"""
6261
Checks the existence of a logic action from the ckanext-validation
6362
plugin, thus supporting any extending of the Validation Plugin class.
63+
6464
Checks ckanext.xloader.validation.requires_successful_report config
6565
option value.
66+
6667
Checks ckanext.xloader.validation.enforce_schema config
6768
option value. Then checks the Resource's validation_status.
6869
"""
@@ -273,7 +274,7 @@ def type_guess(rows, types=TYPES, strict=False):
273274
at_least_one_value = []
274275
for ri, row in enumerate(rows):
275276
diff = len(row) - len(guesses)
276-
for _ in range(diff):
277+
for _i in range(diff):
277278
typesdict = {}
278279
for type in types:
279280
typesdict[type] = 0

0 commit comments

Comments
 (0)