Created
May 2, 2017 18:42
-
-
Save ra-tolson/d09b0a6af0525a9ddc4e899931f44f8a to your computer and use it in GitHub Desktop.
start of work on issue 266 in gips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/gips/inventory/dbinv/api.py b/gips/inventory/dbinv/api.py | |
index 450e56d..1bd06b6 100644 | |
--- a/gips/inventory/dbinv/api.py | |
+++ b/gips/inventory/dbinv/api.py | |
@@ -62,9 +62,8 @@ def rectify_assets(asset_class): | |
def rectify_asset(f_name): # work function for _chunky_transaction() | |
a = asset_class(f_name) | |
(asset, created) = mao.update_or_create( | |
- asset=a.asset, sensor=a.sensor, tile=a.tile, date=a.date, | |
- name=f_name, driver=driver, status='complete' | |
- ) | |
+ driver=driver, asset=a.asset, tile=a.tile, date=a.date, | |
+ defaults=dict(sensor=a.sensor, name=f_name, status='complete')) | |
asset.save() | |
touched_rows.add(asset.pk) | |
if created: | |
@@ -74,6 +73,11 @@ def rectify_assets(asset_class): | |
counts['update'] += 1 | |
verbose_out("Asset found in database: " + f_name, 5) | |
+ def handle_deletia(key): # work function for _chunky_transaction() | |
+ asset = mao.get(pk=key) | |
+ asset.status = 'missing' | |
+ asset.save() | |
+ | |
start_time = time.time() | |
for (ak, av) in asset_class._assets.items(): | |
print "Starting on {} assets at {:0.2f}s".format(ak, time.time() - start_time) | |
@@ -88,11 +92,12 @@ def rectify_assets(asset_class): | |
print "Deleting stale asset records . . . " | |
delete_start_time = time.time() | |
deletia_keys = starting_keys - touched_rows | |
- _chunky_transaction(deletia_keys, lambda key: mao.get(pk=key).delete()) | |
+ # if an asset is in-progress, would it be blasted by the delete step? | |
+ _chunky_transaction(deletia_keys, handle_deletia) | |
delete_time = time.time() - delete_start_time | |
del_cnt = len(deletia_keys) | |
- print "Deleted {} stale asset records in {:0.2f}s.".format(del_cnt, delete_time) | |
+ print "Marked {} stale asset records in {:0.2f}s.".format(del_cnt, delete_time) | |
msg = "{} complete, inventory records changed: {} added, {} updated, {} deleted" | |
print msg.format(ak, counts['add'], counts['update'], del_cnt) # no -v for this important data | |
diff --git a/gips/inventory/dbinv/models.py b/gips/inventory/dbinv/models.py | |
index 53b9d23..30c1c8b 100644 | |
--- a/gips/inventory/dbinv/models.py | |
+++ b/gips/inventory/dbinv/models.py | |
@@ -41,6 +41,8 @@ retry Asset set by worker.fetch when an asset fails to fetch | |
failed Asset set by scheduler when retry count exceeds hardcoded threshold (3) | |
PPJ set by scheduler when it observes an E&A task is busted | |
Job set on the parent Job of a PPJ when its E&A task is marked failed | |
+missing Asset rectify_assets sets this when an asset file is missing | |
+ Product rectify_products sets this when a product file is missing | |
""" | |
status_strings = ('remote', | |
@@ -51,7 +53,9 @@ status_strings = ('remote', | |
'post-processing', # only used at job level | |
'complete', | |
'retry', | |
- 'failed') | |
+ 'failed', | |
+ 'missing', | |
+ ) | |
# TODO: this doesn't do anything because only called if using forms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment