1
- import json
2
1
import logging
3
2
4
3
from pystac_monty .sources .gdacs import (
8
7
)
9
8
10
9
from apps .etl .transform .sources .handler import BaseTransformerHandler
10
+ from apps .etl .utils import write_into_temp_file
11
11
from main .celery import app
12
12
13
13
logger = logging .getLogger (__name__ )
@@ -21,23 +21,34 @@ class GDACSTransformHandler(BaseTransformerHandler[GDACSTransformer, GDACSDataSo
21
21
22
22
@classmethod
23
23
def get_schema_data (cls , extraction_object ):
24
- data = extraction_object .resp_data .read ()
24
+ with extraction_object .resp_data .open ("rb" ) as f :
25
+ file_content = f .read ()
26
+ data_file = write_into_temp_file (file_content )
27
+
25
28
episodes = []
26
29
event_objects = extraction_object .child_extractions .all ()
27
30
for episode_obj in event_objects :
28
31
episodes_data_dict = {}
29
- event_episode_data = episode_obj .resp_data .read ()
30
- episodes_data_dict [GDACSDataSourceType .EVENT ] = (episode_obj .url , json .loads (event_episode_data ))
32
+
33
+ with episode_obj .resp_data .open ("rb" ) as f :
34
+ file_content = f .read ()
35
+ episode_data_temp_file = write_into_temp_file (file_content )
36
+
37
+ episodes_data_dict [GDACSDataSourceType .EVENT ] = (episode_obj .url , episode_data_temp_file .name )
31
38
geometry_objects = episode_obj .child_extractions .all ()
32
39
33
40
for geometry_detail in geometry_objects :
34
- geometry_episode_data = geometry_detail .resp_data .read ()
35
- episodes_data_dict [GDACSDataSourceType .GEOMETRY ] = (geometry_detail .url , json .loads (geometry_episode_data ))
41
+ with geometry_detail .resp_data .open ("rb" ) as f :
42
+ file_content = f .read ()
43
+ geometry_detail_temp_file = write_into_temp_file (file_content )
44
+
45
+ episodes_data_dict [GDACSDataSourceType .GEOMETRY ] = (geometry_detail .url , geometry_detail_temp_file .name )
36
46
37
47
episodes .append (episodes_data_dict )
38
- return cls .transformer_schema (source_url = extraction_object .url , data = json .loads (data ), episodes = episodes )
48
+
49
+ return cls .transformer_schema (source_url = extraction_object .url , data = data_file .name , episodes = episodes )
39
50
40
51
@staticmethod
41
- @app .task
52
+ @app .task ( rate_limit = "50/m" )
42
53
def task (extraction_id ):
43
54
GDACSTransformHandler ().handle_transformation (extraction_id )
0 commit comments