|
38 | 38 | import datetime
|
39 | 39 | import shutil
|
40 | 40 | from functools import wraps
|
| 41 | +import subprocess |
41 | 42 |
|
42 | 43 | from flask import current_app
|
43 | 44 | from shapely.geometry import MultiPolygon
|
|
58 | 59 |
|
59 | 60 | from tyr.minio import MinioWrapper
|
60 | 61 |
|
| 62 | +from tyr.poi_to_excluded_zones import poi_to_excluded_zones |
| 63 | + |
61 | 64 |
|
62 | 65 | def unzip_if_needed(filename):
|
63 | 66 | if not os.path.isdir(filename):
|
@@ -1233,6 +1236,46 @@ def gtfs2s3(self, instance_config, filename, job_id, dataset_uid):
|
1233 | 1236 | _inner_2s3(self, "gtfs", instance_config, filename, job_id, dataset_uid)
|
1234 | 1237 |
|
1235 | 1238 |
|
| 1239 | +@celery.task(bind=True) |
| 1240 | +def poi2asgard(self, instance_config, filename, job_id, dataset_uid): |
| 1241 | + """Extract excluded zones and synchronize with""" |
| 1242 | + job = models.Job.query.get(job_id) |
| 1243 | + dataset = _retrieve_dataset_and_set_state("poi", job.id) |
| 1244 | + instance = job.instance |
| 1245 | + logger = get_instance_logger(instance, task_id=job_id) |
| 1246 | + |
| 1247 | + excluded_zone_dir = "excluded_zones" |
| 1248 | + if os.path.isdir(excluded_zone_dir): |
| 1249 | + shutil.rmtree(excluded_zone_dir) |
| 1250 | + |
| 1251 | + os.mkdir(excluded_zone_dir) |
| 1252 | + poi_to_excluded_zones(filename, excluded_zone_dir, instance.name) |
| 1253 | + |
| 1254 | + try: |
| 1255 | + with collect_metric("poi2Asgard", job, dataset_uid): |
| 1256 | + asgard_bucket = current_app.config.get('MINIO_ASGARD_BUCKET_NAME', None) |
| 1257 | + if not asgard_bucket: |
| 1258 | + raise Exception("Asgard Bucket is None") |
| 1259 | + |
| 1260 | + bash_command = ( |
| 1261 | + "env REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt " |
| 1262 | + "aws s3 sync ./{excluded_zone_dir} s3://{asgard_bucket}/excluded_zones".format( |
| 1263 | + excluded_zone_dir=excluded_zone_dir, asgard_bucket=asgard_bucket |
| 1264 | + ) |
| 1265 | + ) |
| 1266 | + process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE) |
| 1267 | + output, error = process.communicate() |
| 1268 | + if error: |
| 1269 | + raise Exception("Error occurred when putting excluded zones to asgard: {}".format(error)) |
| 1270 | + except: |
| 1271 | + logger.exception("") |
| 1272 | + job.state = "failed" |
| 1273 | + dataset.state = "failed" |
| 1274 | + raise |
| 1275 | + finally: |
| 1276 | + models.db.session.commit() |
| 1277 | + |
| 1278 | + |
1236 | 1279 | def _inner_2s3(self, dataset_type, instance_config, filename, job_id, dataset_uid):
|
1237 | 1280 | job = models.Job.query.get(job_id)
|
1238 | 1281 | dataset = _retrieve_dataset_and_set_state(dataset_type, job.id)
|
|
0 commit comments