Importer
DataImporter
¶
Main manager class for the data importer.
This is where all the action happens and where all the databases, views, and relationships are setup.
Source code in dataimporter/importer.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
__init__(config)
¶
Don't use this init directly, call use_importer above to ensure locking is managed correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
a config object |
required |
Source code in dataimporter/importer.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
add_to_mongo(view_name, everything=False)
¶
Add the queued changes in the given view to MongoDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_name
|
str
|
the name of the view |
required |
everything
|
bool
|
whether to add all records to MongoDB even if they haven't changed. Default: False. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[int]
|
the new version committed, or None if no changes were made |
Source code in dataimporter/importer.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
close()
¶
Close the views and data DBs down.
Source code in dataimporter/importer.py
423 424 425 426 427 428 429 430 | |
force_merge(view_name)
¶
Performs a force merge on the given view name's Elasticsearch indices. This may take a while! This is good for cleaning up deleted documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_name
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in dataimporter/importer.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
get_database(view)
¶
Returns a new SplitgillDatabase instance for the given view. If the view doesn't have an associated SplitgillDatabase name, then a ViewDoesNotHaveDatabase exception is raised. If the view parameter is passed as a str and the view does not exist, a ViewNotFound exception is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
Union[str, View]
|
a View instance or a view's name |
required |
Returns:
| Type | Description |
|---|---|
SplitgillDatabase
|
a SplitgillDatabase instance |
Source code in dataimporter/importer.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
get_store(name)
¶
Get the store with the given name. If the store doesn't exist, a StoreNotFound exception is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the store |
required |
Returns:
| Type | Description |
|---|---|
Store
|
the Store instance |
Source code in dataimporter/importer.py
174 175 176 177 178 179 180 181 182 183 184 185 | |
get_view(name)
¶
Get the view with the given name. If the view doesn't exist, a ViewNotFound exception is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the view |
required |
Returns:
| Type | Description |
|---|---|
View
|
the View instance |
Source code in dataimporter/importer.py
187 188 189 190 191 192 193 194 195 196 197 198 | |
purge_unsuitable_records(view_name)
¶
Delete existing records that no longer match the is_member and is_publishable rules for this view. Depublished records should be handled by the regular ingest process anyway, but this can be used for ad-hoc purging. It will also handle the rarer case of records that are no longer members.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_name
|
str
|
the name of the view to purge records from |
required |
Returns:
| Type | Description |
|---|---|
Tuple[int, int, int]
|
the number of non-member records found, the number of non-publishable records found, and the total count of records deleted by this method |
Source code in dataimporter/importer.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
queue_changes(records, store_name)
¶
Update the records in the store with the given name. The views based on the DB that is being updated will also be updated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
Iterable[SourceRecord]
|
an iterable of records to queue |
required |
store_name
|
str
|
the name of the store to update |
required |
Source code in dataimporter/importer.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
queue_emu_changes()
¶
Look for new EMu dumps and if any are found beyond the date of the last queued EMu import, add the next day's data to the stores and view queues.
Source code in dataimporter/importer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
queue_gbif_changes()
¶
Retrieve the latest GBIF records, check which ones have changed compared to the ones stored in the gbif data DB, and then queue them into the GBIF view.
Source code in dataimporter/importer.py
273 274 275 276 277 278 279 280 281 282 283 284 285 | |
redact_records(store_name, record_ids, redaction_id)
¶
Deletes the given record IDs from the named DataDB. This doesn't delete any data from the views, MongoDB, or Elasticsearch. This will need to be done manually.
This operation should only be performed in extreme circumstances where we need to remove data that should never have been released and should not be searchable at all, even in historic searches. This is because it breaks the core idea of the versioned Splitgill system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store_name
|
str
|
the name of the store to remove the records from |
required |
record_ids
|
List[str]
|
a list of str record IDs to redact |
required |
redaction_id
|
str
|
an ID for the redaction, so it's traceable |
required |
Returns:
| Type | Description |
|---|---|
int
|
the number of records deleted |
Source code in dataimporter/importer.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
release_records(up_to)
¶
Releases embargoed records from each store up to the given up_to value. Released records queued to the views impacted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
up_to
|
int
|
records with an embargo before this timestamp will be released |
required |
Source code in dataimporter/importer.py
307 308 309 310 311 312 313 314 315 | |
sync_to_elasticsearch(view_name, resync=False)
¶
Synchronise the given Splitgill database with Elasticsearch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_name
|
str
|
the name of the view the Splitgill database will use |
required |
resync
|
bool
|
whether to resync all records to Elasticsearch even if they haven't changed |
False
|
Source code in dataimporter/importer.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
EMuStatus
¶
Class controlling the EMu dump status.
Source code in dataimporter/importer.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
__init__(path)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
the file path to store the last date fully imported from EMu |
required |
Source code in dataimporter/importer.py
438 439 440 441 442 | |
clear()
¶
Clear the last date status by deleting the status file.
Source code in dataimporter/importer.py
466 467 468 469 470 | |
get()
¶
Get the last date fully imported from EMu. If no status file is found, return the constant FIRST_VERSION value.
Returns:
| Type | Description |
|---|---|
date
|
a date |
Source code in dataimporter/importer.py
444 445 446 447 448 449 450 451 452 453 454 455 | |
update(last_queued)
¶
Update the last date status value with the given date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_queued
|
date
|
the date to write |
required |
Source code in dataimporter/importer.py
457 458 459 460 461 462 463 464 | |
use_importer(config)
¶
Creates a new DataImporter instance and yields it. Only one instance of the DataImporter class can operate on a given data directory at one time and this function will raise an ImporterAlreadyRunning exception if that is detected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
the config |
required |
Source code in dataimporter/importer.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |