ckanext-xloader 2.3.0__tar.gz → 2.4.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.
Files changed (56) hide show
  1. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/CHANGELOG +11 -0
  2. {ckanext_xloader-2.3.0/ckanext_xloader.egg-info → ckanext_xloader-2.4.0}/PKG-INFO +39 -9
  3. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/README.md +37 -8
  4. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/action.py +11 -36
  5. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/auth.py +3 -2
  6. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/config_declaration.yaml +7 -0
  7. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/db.py +14 -9
  8. ckanext_xloader-2.4.0/ckanext/xloader/interfaces.py +93 -0
  9. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/jobs.py +114 -97
  10. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/loader.py +123 -84
  11. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/parser.py +1 -1
  12. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/plugin.py +2 -0
  13. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_action.py +24 -3
  14. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_chunks.py +33 -34
  15. ckanext_xloader-2.4.0/ckanext/xloader/tests/test_db.py +106 -0
  16. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_jobs.py +35 -14
  17. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_loader.py +113 -0
  18. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_parser.py +29 -0
  19. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/utils.py +17 -4
  20. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0/ckanext_xloader.egg-info}/PKG-INFO +39 -9
  21. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/SOURCES.txt +1 -0
  22. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/pyproject.toml +5 -3
  23. ckanext_xloader-2.3.0/ckanext/xloader/interfaces.py +0 -49
  24. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/LICENSE +0 -0
  25. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/MANIFEST.in +0 -0
  26. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/__init__.py +0 -0
  27. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/__init__.py +0 -0
  28. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/cli.py +0 -0
  29. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/command.py +0 -0
  30. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/helpers.py +0 -0
  31. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/job_exceptions.py +0 -0
  32. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/schema.py +0 -0
  33. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/datastore/snippets/dictionary_form.html +0 -0
  34. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/resource_edit_base.html +0 -0
  35. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/resource_read.html +0 -0
  36. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/snippets/resource_info.html +0 -0
  37. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/snippets/resource_item.html +0 -0
  38. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/snippets/resources.html +0 -0
  39. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/xloader/confirm_datastore_delete.html +0 -0
  40. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/xloader/resource_data.html +0 -0
  41. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/__init__.py +0 -0
  42. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/ckan_setup.py +0 -0
  43. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/fixtures.py +0 -0
  44. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_plugin.py +0 -0
  45. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_utils.py +0 -0
  46. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/views.py +0 -0
  47. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/webassets/css/xloader.css +0 -0
  48. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext/xloader/webassets/webassets.yml +0 -0
  49. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/dependency_links.txt +0 -0
  50. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/entry_points.txt +0 -0
  51. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/requires.txt +0 -0
  52. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/top_level.txt +0 -0
  53. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/dev-requirements.txt +0 -0
  54. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/requirements.txt +0 -0
  55. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/setup.cfg +0 -0
  56. {ckanext_xloader-2.3.0 → ckanext_xloader-2.4.0}/setup.py +0 -0
@@ -2,6 +2,17 @@ CHANGELOG
2
2
  =========
3
3
  See: https://github.com/ckan/ckanext-xloader/releases if this file has drifted.
4
4
 
5
+ 2.3.1 2025-04-30
6
+ ================
7
+
8
+ ## Feat:
9
+
10
+ * #275 Implement a new Interface function for datastore_before_update
11
+
12
+ ## Fix
13
+
14
+ * #274 Qld gov au GitHub 272 extra cells, multiple queues
15
+
5
16
  2.0.1 2025-03-04
6
17
  ================
7
18
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ckanext-xloader
3
- Version: 2.3.0
3
+ Version: 2.4.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>
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.7
15
15
  Classifier: Programming Language :: Python :: 3.8
16
16
  Classifier: Programming Language :: Python :: 3.9
17
17
  Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.14
18
19
  Description-Content-Type: text/markdown
19
20
  License-File: LICENSE
20
21
  Requires-Dist: typing_extensions
@@ -136,13 +137,14 @@ type -offers to contribute this are welcomed.
136
137
 
137
138
  Compatibility with core CKAN versions:
138
139
 
139
- | CKAN version | Compatibility |
140
- | -------------- |-------------------------------------------------------|
141
- | 2.7 | no longer supported (last supported version: 0.12.2) |
142
- | 2.8 | no longer supported (last supported version: 0.12.2) |
143
- | 2.9 | no longer supported (last supported version: 1.2.x) |
144
- | 2.10 | yes |
145
- | 2.11 | yes |
140
+ | CKAN version | Compatibility |
141
+ |--------------|-------------------------------------------------------|
142
+ | 2.7 | no longer supported (last supported version: 0.12.2) |
143
+ | 2.8 | no longer supported (last supported version: 0.12.2) |
144
+ | 2.9 | no longer supported (last supported version: 1.2.x) |
145
+ | 2.10 | yes |
146
+ | 2.11 | yes |
147
+ | 2.12 | yes |
146
148
 
147
149
  ## Installation
148
150
 
@@ -277,6 +279,20 @@ Default value: `1000000000`
277
279
 
278
280
  The maximum file size that XLoader will attempt to load.
279
281
 
282
+ #### ckanext.xloader.queue_names
283
+
284
+ Example:
285
+
286
+ ```
287
+ ckanext.xloader.queue_names = foo baz
288
+ ```
289
+
290
+ Default value: `default`
291
+
292
+ A whitespace-separated list of worker queues that XLoader jobs can be sent to.
293
+
294
+ By default, jobs for the same package will be sent to the same queue,
295
+ to reduce database lock contention.
280
296
 
281
297
  #### ckanext.xloader.use_type_guessing
282
298
 
@@ -433,6 +449,20 @@ Controls whether or not the status badges display all of the statuses. By defaul
433
449
  the badges will display "pending", "running", and "error". With debug_badges enabled,
434
450
  they will also display "complete", "active", "inactive", and "unknown".
435
451
 
452
+ #### ckanext.xloader.queue_names
453
+
454
+ Example:
455
+
456
+ ```
457
+ ckanext.xloader.queue_names = foo,baz
458
+ ```
459
+
460
+ Default value: 'default'
461
+
462
+ Defines the queue(s) available to use for XLoader jobs.
463
+ Jobs for the same package will be sent to the same queue,
464
+ to reduce lock contention.
465
+
436
466
  #### ckanext.xloader.validation.requires_successful_report
437
467
 
438
468
  Supports: __ckanext-validation__
@@ -464,7 +494,7 @@ Controls whether or not a resource requires a Validation Schema to be present fr
464
494
  #### ckanext.xloader.site_url
465
495
  Provide an alternate site URL for the xloader_submit action.
466
496
  This is useful, for example, when the site is running within a docker network.
467
-
497
+
468
498
  Note: This setting will not alter path. i.e ckan.root_path
469
499
 
470
500
  Example:
@@ -112,13 +112,14 @@ type -offers to contribute this are welcomed.
112
112
 
113
113
  Compatibility with core CKAN versions:
114
114
 
115
- | CKAN version | Compatibility |
116
- | -------------- |-------------------------------------------------------|
117
- | 2.7 | no longer supported (last supported version: 0.12.2) |
118
- | 2.8 | no longer supported (last supported version: 0.12.2) |
119
- | 2.9 | no longer supported (last supported version: 1.2.x) |
120
- | 2.10 | yes |
121
- | 2.11 | yes |
115
+ | CKAN version | Compatibility |
116
+ |--------------|-------------------------------------------------------|
117
+ | 2.7 | no longer supported (last supported version: 0.12.2) |
118
+ | 2.8 | no longer supported (last supported version: 0.12.2) |
119
+ | 2.9 | no longer supported (last supported version: 1.2.x) |
120
+ | 2.10 | yes |
121
+ | 2.11 | yes |
122
+ | 2.12 | yes |
122
123
 
123
124
  ## Installation
124
125
 
@@ -253,6 +254,20 @@ Default value: `1000000000`
253
254
 
254
255
  The maximum file size that XLoader will attempt to load.
255
256
 
257
+ #### ckanext.xloader.queue_names
258
+
259
+ Example:
260
+
261
+ ```
262
+ ckanext.xloader.queue_names = foo baz
263
+ ```
264
+
265
+ Default value: `default`
266
+
267
+ A whitespace-separated list of worker queues that XLoader jobs can be sent to.
268
+
269
+ By default, jobs for the same package will be sent to the same queue,
270
+ to reduce database lock contention.
256
271
 
257
272
  #### ckanext.xloader.use_type_guessing
258
273
 
@@ -409,6 +424,20 @@ Controls whether or not the status badges display all of the statuses. By defaul
409
424
  the badges will display "pending", "running", and "error". With debug_badges enabled,
410
425
  they will also display "complete", "active", "inactive", and "unknown".
411
426
 
427
+ #### ckanext.xloader.queue_names
428
+
429
+ Example:
430
+
431
+ ```
432
+ ckanext.xloader.queue_names = foo,baz
433
+ ```
434
+
435
+ Default value: 'default'
436
+
437
+ Defines the queue(s) available to use for XLoader jobs.
438
+ Jobs for the same package will be sent to the same queue,
439
+ to reduce lock contention.
440
+
412
441
  #### ckanext.xloader.validation.requires_successful_report
413
442
 
414
443
  Supports: __ckanext-validation__
@@ -440,7 +469,7 @@ Controls whether or not a resource requires a Validation Schema to be present fr
440
469
  #### ckanext.xloader.site_url
441
470
  Provide an alternate site URL for the xloader_submit action.
442
471
  This is useful, for example, when the site is running within a docker network.
443
-
472
+
444
473
  Note: This setting will not alter path. i.e ckan.root_path
445
474
 
446
475
  Example:
@@ -5,10 +5,11 @@ import datetime
5
5
  import json
6
6
  import logging
7
7
 
8
- import ckan.lib.jobs as rq_jobs
8
+ from ckan.lib.jobs import get_queue
9
9
  import ckan.lib.navl.dictization_functions
10
10
  from ckan.logic import side_effect_free
11
11
  import ckan.plugins as p
12
+ from ckan.plugins.toolkit import config, enqueue_job, get_or_bust
12
13
  from dateutil.parser import parse as parse_date
13
14
  from dateutil.parser import isoparse as parse_iso_date
14
15
 
@@ -16,13 +17,8 @@ import ckanext.xloader.schema
16
17
 
17
18
  from . import interfaces as xloader_interfaces, jobs, db, utils
18
19
 
19
- enqueue_job = p.toolkit.enqueue_job
20
- get_queue = rq_jobs.get_queue
21
-
22
20
  log = logging.getLogger(__name__)
23
- config = p.toolkit.config
24
21
 
25
- _get_or_bust = p.toolkit.get_or_bust
26
22
  _validate = ckan.lib.navl.dictization_functions.validate
27
23
 
28
24
 
@@ -48,7 +44,6 @@ def xloader_submit(context, data_dict):
48
44
  '''
49
45
  p.toolkit.check_access('xloader_submit', context, data_dict)
50
46
  api_key = utils.get_xloader_user_apitoken()
51
- custom_queue = data_dict.pop('queue', rq_jobs.DEFAULT_QUEUE_NAME)
52
47
  schema = context.get('schema', ckanext.xloader.schema.xloader_submit_schema())
53
48
  data_dict, errors = _validate(data_dict, schema, context)
54
49
  if errors:
@@ -68,6 +63,8 @@ def xloader_submit(context, data_dict):
68
63
  })
69
64
  except p.toolkit.ObjectNotFound:
70
65
  return False
66
+ package_id = resource_dict.get('package_id')
67
+ custom_queue = data_dict.pop('queue', jobs.get_default_queue_name(package_id))
71
68
 
72
69
  for plugin in p.PluginImplementations(xloader_interfaces.IXloader):
73
70
  upload = plugin.can_upload(res_id)
@@ -158,11 +155,12 @@ def xloader_submit(context, data_dict):
158
155
  'set_url_type': data_dict.get('set_url_type', False),
159
156
  'task_created': task['last_updated'],
160
157
  'original_url': resource_dict.get('url'),
158
+ 'queue_name': custom_queue,
161
159
  }
162
160
  }
163
- if custom_queue != rq_jobs.DEFAULT_QUEUE_NAME:
161
+ if custom_queue not in jobs.default_queue_names:
164
162
  # Don't automatically retry if it's a custom run
165
- data['metadata']['tries'] = jobs.MAX_RETRIES
163
+ data['metadata']['tries'] = jobs.max_retries
166
164
 
167
165
  # Expand timeout for resources that have to be type-guessed
168
166
  timeout = config.get(
@@ -173,7 +171,7 @@ def xloader_submit(context, data_dict):
173
171
  try:
174
172
  job = enqueue_job(
175
173
  jobs.xloader_data_into_datastore, [data], queue=custom_queue,
176
- title="xloader_submit: package: {} resource: {}".format(resource_dict.get('package_id'), res_id),
174
+ title="xloader_submit: package: {} resource: {}".format(package_id, res_id),
177
175
  rq_kwargs=dict(timeout=timeout, at_front=sync)
178
176
  )
179
177
  except Exception:
@@ -200,29 +198,6 @@ def xloader_submit(context, data_dict):
200
198
  return True
201
199
 
202
200
 
203
- def _enqueue(fn, args=None, kwargs=None, title=None, queue='default',
204
- timeout=180):
205
- '''Same as latest ckan.lib.jobs.enqueue - earlier CKAN versions dont have
206
- the timeout param
207
-
208
- This function can be removed when dropping support for 2.7
209
- '''
210
- if args is None:
211
- args = []
212
- if kwargs is None:
213
- kwargs = {}
214
- job = get_queue(queue).enqueue_call(func=fn, args=args, kwargs=kwargs,
215
- timeout=timeout)
216
- job.meta[u'title'] = title
217
- job.save()
218
- msg = u'Added background job {}'.format(job.id)
219
- if title:
220
- msg = u'{} ("{}")'.format(msg, title)
221
- msg = u'{} to queue "{}"'.format(msg, queue)
222
- log.info(msg)
223
- return job
224
-
225
-
226
201
  def xloader_hook(context, data_dict):
227
202
  ''' Update xloader task. This action is typically called by ckanext-xloader
228
203
  whenever the status of a job changes.
@@ -254,9 +229,9 @@ def xloader_hook(context, data_dict):
254
229
 
255
230
  '''
256
231
 
257
- metadata, status = _get_or_bust(data_dict, ['metadata', 'status'])
232
+ metadata, status = get_or_bust(data_dict, ['metadata', 'status'])
258
233
 
259
- res_id = _get_or_bust(metadata, 'resource_id')
234
+ res_id = get_or_bust(metadata, 'resource_id')
260
235
 
261
236
  # Pass metadata, not data_dict, as it contains the resource id needed
262
237
  # on the auth checks
@@ -338,7 +313,7 @@ def xloader_status(context, data_dict):
338
313
 
339
314
  if 'id' in data_dict:
340
315
  data_dict['resource_id'] = data_dict['id']
341
- res_id = _get_or_bust(data_dict, 'resource_id')
316
+ res_id = get_or_bust(data_dict, 'resource_id')
342
317
 
343
318
  task = p.toolkit.get_action('task_status_show')(context, {
344
319
  'entity_id': res_id,
@@ -1,5 +1,6 @@
1
1
  from ckan import authz
2
- from ckan.lib import jobs as rq_jobs
2
+
3
+ from .jobs import default_queue_names
3
4
 
4
5
  import ckanext.datastore.logic.auth as auth
5
6
 
@@ -7,7 +8,7 @@ import ckanext.datastore.logic.auth as auth
7
8
  def xloader_submit(context, data_dict):
8
9
  # only sysadmins can specify a custom processing queue
9
10
  custom_queue = data_dict.get('queue')
10
- if custom_queue and custom_queue != rq_jobs.DEFAULT_QUEUE_NAME:
11
+ if custom_queue and custom_queue not in default_queue_names:
11
12
  return authz.is_authorized('config_option_update', context, data_dict)
12
13
  return auth.datastore_auth(context, data_dict)
13
14
 
@@ -163,6 +163,13 @@ groups:
163
163
 
164
164
  See https://github.com/frictionlessdata/ckanext-validation?tab=readme-ov-file#data-schema
165
165
  for more details.
166
+ - key: ckanext.xloader.queue_names
167
+ default: default
168
+ example: foo baz
169
+ description: |
170
+ A whitespace-separated list of queues to enqueue XLoader jobs to.
171
+ Jobs for the same package will be sent to the same queue.
172
+ required: false
166
173
  - key: ckanext.xloader.clean_datastore_tables
167
174
  default: False
168
175
  example: True
@@ -11,7 +11,6 @@ import json
11
11
  import six
12
12
  import sqlalchemy
13
13
 
14
-
15
14
  ENGINE = None
16
15
  _METADATA = None
17
16
  JOBS_TABLE = None
@@ -111,17 +110,19 @@ def get_job(job_id):
111
110
  if job_id:
112
111
  job_id = six.text_type(job_id)
113
112
 
113
+ if JOBS_TABLE is None or ENGINE is None:
114
+ raise RuntimeError("DB is not initialized")
115
+
116
+ stmt = sqlalchemy.select(JOBS_TABLE).where(JOBS_TABLE.c.job_id == job_id)
114
117
  with ENGINE.connect() as conn:
115
- result = conn.execute(
116
- JOBS_TABLE.select().where(JOBS_TABLE.c.job_id == job_id)
117
- ).first()
118
+ result = conn.execute(stmt).first()
118
119
 
119
120
  if not result:
120
121
  return None
121
122
 
122
123
  # Turn the result into a dictionary representation of the job.
123
124
  result_dict = {}
124
- for field in list(result.keys()):
125
+ for field in stmt.columns.keys():
125
126
  value = getattr(result, field)
126
127
  if value is None:
127
128
  result_dict[field] = value
@@ -445,6 +446,8 @@ def _get_metadata(job_id):
445
446
  # Avoid SQLAlchemy "Unicode type received non-unicode bind param value"
446
447
  # warnings.
447
448
  job_id = six.text_type(job_id)
449
+ if ENGINE is None or METADATA_TABLE is None:
450
+ raise RuntimeError("DB is not initialized")
448
451
 
449
452
  with ENGINE.connect() as conn:
450
453
  results = conn.execute(
@@ -452,10 +455,10 @@ def _get_metadata(job_id):
452
455
  METADATA_TABLE.c.job_id == job_id)).fetchall()
453
456
  metadata = {}
454
457
  for row in results:
455
- value = row['value']
456
- if row['type'] == 'json':
458
+ value = row.value
459
+ if row.type == 'json':
457
460
  value = json.loads(value)
458
- metadata[row['key']] = value
461
+ metadata[row.key] = value
459
462
  return metadata
460
463
 
461
464
 
@@ -464,12 +467,14 @@ def _get_logs(job_id):
464
467
  # Avoid SQLAlchemy "Unicode type received non-unicode bind param value"
465
468
  # warnings.
466
469
  job_id = six.text_type(job_id)
470
+ if ENGINE is None or LOGS_TABLE is None:
471
+ raise RuntimeError("DB is not initialized")
467
472
 
468
473
  with ENGINE.connect() as conn:
469
474
  results = conn.execute(
470
475
  LOGS_TABLE.select().where(LOGS_TABLE.c.job_id == job_id)).fetchall()
471
476
 
472
- results = [dict(result) for result in results]
477
+ results = [dict(result._mapping) for result in results] # pyright: ignore[reportPrivateUsage]
473
478
 
474
479
  for result in results:
475
480
  result.pop("job_id")
@@ -0,0 +1,93 @@
1
+ from ckan.plugins.interfaces import Interface
2
+
3
+
4
+ class IXloader(Interface):
5
+ """
6
+ The IXloader interface allows plugin authors to receive notifications
7
+ before and after a resource is submitted to the xloader service, as
8
+ well as determining whether a resource should be submitted in can_upload
9
+
10
+ The before_submit function, when implemented
11
+ """
12
+
13
+ def can_upload(self, resource_id):
14
+ """ This call when implemented can be used to stop the processing of
15
+ the xloader submit function. This method will not be called if
16
+ the resource format does not match those defined in the
17
+ ckanext.xloader.formats config option or the default formats.
18
+
19
+ If this function returns False then processing will be aborted,
20
+ whilst returning True will submit the resource to the xloader
21
+ service
22
+
23
+ Note that before reaching this hook there is a prior check on the
24
+ resource format, which depends on the value of
25
+ the :ref:`ckanext.xloader.formats` configuration option (and requires
26
+ the resource to have a format defined).
27
+
28
+ :param resource_id: The ID of the resource that is to be
29
+ pushed to the xloader service.
30
+
31
+ Returns ``True`` if the job should be submitted and ``False`` if
32
+ the job should be aborted
33
+
34
+ :rtype: bool
35
+ """
36
+ return True
37
+
38
+ def after_upload(self, context, resource_dict, dataset_dict):
39
+ """ After a resource has been successfully upload to the datastore
40
+ this method will be called with the resource dictionary and the
41
+ package dictionary for this resource.
42
+
43
+ :param context: The context within which the upload happened
44
+ :param resource_dict: The dict represenstaion of the resource that was
45
+ successfully uploaded to the datastore
46
+ :param dataset_dict: The dict represenstation of the dataset containing
47
+ the resource that was uploaded
48
+ """
49
+ pass
50
+
51
+ def datastore_before_update(self, resource_id, existing_fields, new_headers):
52
+ """ Called by the loader just before it is about to modify the
53
+ DataStore table for a resource (truncate, drop+recreate, or create).
54
+ It allows plugins to inspect the difference between the current
55
+ DataStore columns and the ones detected in the incoming file, for
56
+ example to log an activity when columns are added, removed or
57
+ renamed.
58
+
59
+ Both ``existing_fields`` and ``new_headers`` are lists of field
60
+ dicts that contain at least an ``id`` key, so a plugin can compute
61
+ the diff symmetrically::
62
+
63
+ old_ids = {f['id'] for f in existing_fields or []}
64
+ new_ids = {h['id'] for h in new_headers}
65
+ added = new_ids - old_ids
66
+ removed = old_ids - new_ids
67
+
68
+ :param resource_id: the ID of the resource whose DataStore table is
69
+ about to be updated.
70
+ :type resource_id: string
71
+
72
+ :param existing_fields: the current columns of the DataStore table
73
+ (the internal ``_id`` column is excluded), or ``None`` if the
74
+ DataStore table does not yet exist. Each dict contains at least
75
+ ``id`` and ``type`` and may include ``info`` for fields with a
76
+ Data Dictionary entry.
77
+ :type existing_fields: list of dicts or None
78
+
79
+ :param new_headers: the list of field dicts that will be written to
80
+ the DataStore. Each dict has at least an ``id`` and ``type``
81
+ key, and may include an ``info`` dict for fields that already
82
+ existed.
83
+ :type new_headers: list of dicts
84
+
85
+ The ``new_headers`` param is the same list the loader will use after the
86
+ hook returns, so mutating it (adding, removing, renaming fields)
87
+ will affect the subsequent DataStore operation.
88
+ The ``existing_fields`` is a snapshot with the internal ``_id`` column
89
+ excluded and should be treated as read-only.
90
+
91
+ The return value is ignored.
92
+ """
93
+ pass