@@ -68,46 +68,41 @@ def pre(context)
68
68
return true
69
69
end
70
70
71
+ def metis_filesystem
72
+ Etna ::Filesystem ::Metis . new (
73
+ project_name : project_name ,
74
+ bucket_name : bucket_name ,
75
+ metis_client : metis_client ,
76
+ root : metis_root_path
77
+ )
78
+ end
79
+
80
+ def ingest_filesystem
81
+ Etna ::Filesystem ::SftpFilesystem . new (
82
+ username : config [ "secrets" ] [ "sftp_ingest_user" ] ,
83
+ password : config [ "secrets" ] [ "sftp_ingest_password" ] ,
84
+ host : config [ "secrets" ] [ "sftp_ingest_host" ]
85
+ )
86
+ end
87
+
71
88
def process ( context )
72
89
context [ :failed_files ] = [ ]
73
90
74
- context [ :files_to_update ] . each do |file |
75
- sftp_path = file [ :path ]
76
- modified_time = file [ :modified_time ]
77
-
78
- begin
79
- file_stream = sftp_client . download_as_stream ( sftp_path )
80
- if file_stream . nil?
81
- logger . info ( "Failed to download #{ sftp_path } " )
82
- next
83
- end
84
- rescue StandardError => e
85
- logger . info ( "Failed to download from sftp server, #{ sftp_path } : #{ e . message } " )
86
- context [ :failed_files ] << sftp_path
87
- next
88
- end
91
+ workflow = Etna ::Clients ::Metis ::IngestMetisDataWorkflow . new (
92
+ metis_filesystem : metis_filesystem ,
93
+ ingest_filesystem : ingest_filesystem ,
94
+ logger : nil ,
95
+ )
89
96
90
- begin
91
- uploader = Etna ::Clients ::Metis ::MetisUploadWorkflow . new (
92
- metis_client : metis_client ,
93
- project_name : project_name ,
94
- bucket_name : bucket_name ,
95
- metis_uid : metis_uid ,
96
- )
97
-
98
- metis_path = File . join ( metis_root_path , sftp_path . gsub ( name_regex , '' ) )
99
- uploader . do_upload (
100
- Etna ::Clients ::Metis ::MetisUploadWorkflow ::StreamingIOUpload . new (
101
- readable_io : file_stream ,
102
- size_hint : file_stream . size ,
103
- ) ,
104
- metis_path
105
- )
106
- rescue StandardError => e
107
- logger . warn ( "Failed to upload to metis: #{ metis_path } . Error: #{ e . message } " )
108
- context [ :failed_files ] << sftp_path
97
+ workflow . copy_files ( context [ :files_to_update ] . map do |file |
98
+ [ file [ :path ] , file [ :path ] . gsub ( name_regex , '' ) ]
99
+ end ) do |filename , success |
100
+ if success
101
+ context [ :successful_files ] << filename
102
+ else
103
+ logger . warn ( "Failed to upload to metis: #{ filename } " )
104
+ context [ :failed_files ] << filename
109
105
end
110
-
111
106
end
112
107
end
113
108
0 commit comments