@@ -150,22 +150,29 @@ def change_run_status(self, new_status, end_date=None):
150150
151151 self .session .commit ()
152152
153+ if (
154+ self .process_status_types [new_status ] == self .process_status_complete
155+ ) or (self .process_status_types [new_status ] == self .process_status_failed ):
156+ self .session .close ()
157+
153158 else :
154159 raise Exception ("The provided status type %s is invalid." % new_status )
155160
156- def find_ready_extracts_by_filename (self , filename ):
161+ def find_extracts_by_filename (self , filename , status = "ready" ):
157162 """
158163 For the given filename, or filename part, find all matching extracts that are ready for processing.
159-
160- :param filename:
161- :return:
164+ :param filename: Filename or part of filename.
165+ :type filename: str
166+ :param status: Name of the status type for files being searched. Default 'ready'.
167+ :type status: str
168+ :return: List of Extract SQLAlchemy objects.
162169 """
163170
164171 process_files = (
165172 self .session .query (Extract )
166173 .join (ExtractStatus )
167174 .filter (Extract .extract_filename .like ("%" + filename + "%" ))
168- .filter (ExtractStatus .extract_status_name == "ready" )
175+ .filter (ExtractStatus .extract_status_name == status )
169176 .order_by (Extract .extract_registration_date_time )
170177 .order_by (Extract .extract_id )
171178 .all ()
@@ -175,22 +182,26 @@ def find_ready_extracts_by_filename(self, filename):
175182
176183 return process_files
177184
178- def find_ready_extracts_by_location (self , location_name = None , location_path = None ):
185+ def find_extracts_by_location (
186+ self , location_name = None , location_path = None , status = "ready"
187+ ):
179188 """
180189 For the given location path or location name, find all matching extracts that are ready for processing
181190 :param location_name: The name of the location
182191 :type location_name: str
183192 :param location_path: The path of the location
184193 :type location_path: str
185- :return: List of extract files that are in 'ready' state'.
194+ :param status: Name of the status type for files being searched. Default 'ready'.
195+ :type status: str
196+ :return: List of Extract SQLAlchemy objects.
186197 """
187198
188199 if location_path is not None :
189200 process_files = (
190201 self .session .query (Extract )
191202 .join (Location )
192203 .join (ExtractStatus )
193- .filter (ExtractStatus .extract_status_name == "ready" )
204+ .filter (ExtractStatus .extract_status_name == status )
194205 .filter (Location .location_path == location_path )
195206 .order_by (Extract .extract_registration_date_time )
196207 .order_by (Extract .extract_id )
@@ -201,7 +212,7 @@ def find_ready_extracts_by_location(self, location_name=None, location_path=None
201212 self .session .query (Extract )
202213 .join (Location )
203214 .join (ExtractStatus )
204- .filter (ExtractStatus .extract_status_name == "ready" )
215+ .filter (ExtractStatus .extract_status_name == status )
205216 .filter (Location .location_name == location_name )
206217 .order_by (Extract .extract_registration_date_time )
207218 .order_by (Extract .extract_id )
@@ -218,10 +229,14 @@ def find_ready_extracts_by_location(self, location_name=None, location_path=None
218229 self .logger .info ("Returning extract files by location." )
219230 return process_files
220231
221- def find_ready_extracts_by_process (self , extract_process_name ):
232+ def find_extracts_by_process (self , extract_process_name , status = "ready" ):
222233 """
223234 For the given named process, find the extracts that are ready for processing.
224- :return: List of OS specific filepaths with filenames.
235+ :param extract_process_name: Name of the process that is associated with extracts
236+ :type extract_process_name: str
237+ :param status: Name of the status type for files being searched. Default 'ready'.
238+ :type status: str
239+ :return: List of Extract SQLAlchemy objects.
225240 """
226241
227242 process_files = (
@@ -238,7 +253,7 @@ def find_ready_extracts_by_process(self, extract_process_name):
238253 .join (Process )
239254 .filter (
240255 Process .process_name == extract_process_name ,
241- ExtractStatus .extract_status_name == "ready" ,
256+ ExtractStatus .extract_status_name == status ,
242257 )
243258 .order_by (Extract .extract_registration_date_time )
244259 .all ()
0 commit comments