Skip to content

Commit 1b0360c

Browse files
committed
fix logic in determine_job_version
1 parent d5d2ee6 commit 1b0360c

1 file changed

Lines changed: 28 additions & 19 deletions

File tree

sds_data_manager/lambda_code/SDSCode/pipeline_lambdas/batch_starter.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -198,43 +198,52 @@ def filter_conditions(table):
198198
)
199199
return conditions
200200

201-
# First check to see if there are any jobs in progress and get the max version
201+
# Step 1: query to get the max version from the processing jobs table
202202
max_version_record = (
203203
session.query(models.ProcessingJob)
204204
.filter(*filter_conditions(models.ProcessingJob))
205205
.order_by(models.ProcessingJob.version.desc())
206206
.first()
207207
)
208208
if max_version_record:
209-
max_version = max_version_record.version
210-
# If there is a job already in progress, determine whether the current job
211-
# is a duplicate of the in-progress job by checking the dependency file hash.
212-
# If the hashes are different, then we know the dependencies have changed and
213-
# we should bump the version number and continue with processing.
209+
max_version_proc = max_version_record.version
210+
# Step 2: If there is a job already in progress, determine whether the current
211+
# job is a duplicate of the in-progress job by checking the dependency file
212+
# hash. If the hashes are different, then we know the dependencies have changed
213+
# and we should bump the version number and continue with processing.
214214
if max_version_record.status == models.Status.INPROGRESS:
215215
command = max_version_record.container_command
216216
if dependency_hash(current_dependencies) in command:
217217
# Return the current max version and this job will not proceed if
218218
# everything else is the same.
219-
return max_version
219+
return max_version_proc
220220
logger.info(
221221
f"Job with id: {max_version_record.id} is in progress, but the "
222222
f"dependencies have changed. Bumping version number."
223223
)
224224
else:
225-
max_version = None
226-
# If the descriptor is "all", we should only check the processing job table. The
227-
# ScienceFiles table does not have descriptors of "all" since the products
228-
# produced will have their own specific descriptors.
225+
max_version_proc = None
226+
# Step 3: If the descriptor is "all", only use the max version from the processing
227+
# job table. The ScienceFiles table does not have descriptors of "all" since the
228+
# products produced will have their own specific descriptors.
229229
if descriptor == "all":
230-
return f"v{int(max_version[1:]) + 1:03d}" if max_version else "v001"
231-
# If no jobs are in progress, check the science files table for the max version.
232-
if not max_version:
233-
max_version = (
234-
session.query(func.max(models.ScienceFiles.version)).filter(
235-
*filter_conditions(models.ScienceFiles)
236-
)
237-
).scalar()
230+
return f"v{int(max_version_proc[1:]) + 1:03d}" if max_version_proc else "v001"
231+
232+
# Step 4: Get the max version from the science files table.
233+
max_version_sci = (
234+
session.query(func.max(models.ScienceFiles.version)).filter(
235+
*filter_conditions(models.ScienceFiles)
236+
)
237+
).scalar()
238+
239+
# Step 5: By default, use the max version from the science files table unless
240+
# it is None. If None, then use the max version from the processing jobs
241+
# table. For example, if the job is a spacecraft pointing-attitude job, it will
242+
# produce a SPICE kernel and not a science file. There is no way to determine the
243+
# filename of the kernel that will be produced, so we rely on the max version from
244+
# the processing jobs table.
245+
max_version = max_version_sci if max_version_sci else max_version_proc
246+
238247
# Bump the version number. "V001" will be returned if max_version is None.
239248
return f"v{int(max_version[1:]) + 1:03d}" if max_version else "v001"
240249

0 commit comments

Comments
 (0)