Find cache database using task parents
The endpoint RetrieveTaskFromAgent
should give access to the task parents from the current task:
- when
use_cache
is True - hit that endpoint during
configure
and store the parent IDs - merge step:
- if there is only one parent task, copy that file into the
/data/current
folder - otherwise, merge immediately all the database files into a single one into the
/data/current
folder
- if there is only one parent task, copy that file into the
merge code
def merge_databases(source_db, dest_db):
"""
Low-level method to merge two mbtiles (sqlite databases)
"""
assert os.path.exists(source_db)
assert os.path.exists(dest_db)
statements = [
"PRAGMA journal_mode=PERSIST;",
"PRAGMA page_size=80000;",
"PRAGMA synchronous=OFF;",
"ATTACH DATABASE '{}' AS source;".format(source_db),
"REPLACE INTO map SELECT * FROM source.map;",
"REPLACE INTO images SELECT * FROM source.images;",
]
connection = sqlite3.connect(dest_db)
cursor = connection.cursor()
for statement in statements:
cursor.execute(statement)
connection.commit()
connection.close()