@@ -180,43 +180,63 @@ def filter_conditions(table):
180180 )
181181 return conditions
182182
183- # First check to see if there are any jobs in progress and get the max version
183+ # Step 1: query to get the max version from the processing jobs table
184184 max_version_record = (
185185 session .query (models .ProcessingJob )
186186 .filter (* filter_conditions (models .ProcessingJob ))
187187 .order_by (models .ProcessingJob .version .desc ())
188188 .first ()
189189 )
190190 if max_version_record :
191- max_version = max_version_record .version
192- # If there is a job already in progress, determine whether the current job
193- # is a duplicate of the in-progress job by checking the dependency file hash.
194- # If the hashes are different, then we know the dependencies have changed and
195- # we should bump the version number and continue with processing.
191+ max_version_processing = max_version_record .version
192+ # Step 2: If there is a job already in progress, determine whether the current
193+ # job is a duplicate of the in-progress job by checking the dependency file
194+ # hash. If the hashes are different, then we know the dependencies have changed
195+ # and we should bump the version number and continue with processing.
196196 if max_version_record .status == models .Status .INPROGRESS :
197197 command = max_version_record .container_command
198198 if dependency_hash (current_dependencies ) in command :
199199 # Return the current max version and this job will not proceed if
200200 # everything else is the same.
201- return max_version
202- logger .info (
203- f"Job with id: { max_version_record .id } is in progress, but the "
204- f"dependencies have changed. Bumping version number."
205- )
201+ return max_version_processing
202+ else :
203+ # Dependencies have changed, so bump the version number.
204+ logger .info (
205+ f"Job with id: { max_version_record .id } is in progress, but the "
206+ f"dependencies have changed. Bumping version number."
207+ )
208+ return f"v{ int (max_version_processing [1 :]) + 1 :03d} "
209+
206210 else :
207- max_version = None
208- # If the descriptor is "all", we should only check the processing job table. The
209- # ScienceFiles table does not have descriptors of "all" since the products
210- # produced will have their own specific descriptors.
211- if descriptor == "all" :
212- return f"v{ int (max_version [1 :]) + 1 :03d} " if max_version else "v001"
213- # If no jobs are in progress, check the science files table for the max version.
214- if not max_version :
215- max_version = (
216- session .query (func .max (models .ScienceFiles .version )).filter (
217- * filter_conditions (models .ScienceFiles )
218- )
219- ).scalar ()
211+ max_version_processing = None
212+ # Step 3: If the descriptor is "all", only use the max version from the processing
213+ # job table. The ScienceFiles table does not have descriptors of "all" since the
214+ # products produced will have their own specific descriptors.
215+ if "all" in descriptor :
216+ return (
217+ f"v{ int (max_version_processing [1 :]) + 1 :03d} "
218+ if max_version_processing
219+ else "v001"
220+ )
221+
222+ # Step 4: Get the max version from the science files table.
223+ max_version_sci = (
224+ session .query (func .max (models .ScienceFiles .version )).filter (
225+ * filter_conditions (models .ScienceFiles )
226+ )
227+ ).scalar ()
228+
229+ # Step 5: By default, use the max version from the science files table unless
230+ # it is a spacecraft "pointing-attitude" job. If a so, then use the max version
231+ # from the processing jobs table. If the job is a spacecraft pointing-attitude job,
232+ # it will produce a SPICE kernel and not a science file. There is no way to
233+ # determine the filename of the kernel that will be produced, so we rely on the max
234+ # version from the processing jobs table.
235+ if instrument == "spacecraft" and descriptor == "pointing-attitude" :
236+ max_version = max_version_processing
237+ else :
238+ max_version = max_version_sci
239+
220240 # Bump the version number. "V001" will be returned if max_version is None.
221241 return f"v{ int (max_version [1 :]) + 1 :03d} " if max_version else "v001"
222242
0 commit comments