diff --git a/components/job-orchestration/job_orchestration/scheduler/search/search_scheduler.py b/components/job-orchestration/job_orchestration/scheduler/search/search_scheduler.py index b4221ff95..7f4107d22 100644 --- a/components/job-orchestration/job_orchestration/scheduler/search/search_scheduler.py +++ b/components/job-orchestration/job_orchestration/scheduler/search/search_scheduler.py @@ -459,6 +459,8 @@ async def check_job_status_and_update_db(db_conn_pool, results_cache_uri): error_msg = f"Unexpected msg_type: {msg.msg_type.name}" raise NotImplementedError(error_msg) + # We set the status regardless of the job's previous status to handle the case where the + # job is cancelled (status = CANCELLING) while we're in this method. if set_job_status(db_conn, job_id, new_job_status): if new_job_status == SearchJobStatus.SUCCEEDED: logger.info(f"Completed job {job_id}.") diff --git a/components/webui/imports/api/search/server/SearchJobsDbManager.js b/components/webui/imports/api/search/server/SearchJobsDbManager.js index 8f5f950e7..df1dc27fa 100644 --- a/components/webui/imports/api/search/server/SearchJobsDbManager.js +++ b/components/webui/imports/api/search/server/SearchJobsDbManager.js @@ -90,8 +90,8 @@ class SearchJobsDbManager { await this.#sqlDbConnPool.query( `UPDATE ${this.#searchJobsTableName} SET ${SEARCH_JOBS_TABLE_COLUMN_NAMES.STATUS} = ${SEARCH_JOB_STATUS.CANCELLING} - WHERE ${SEARCH_JOBS_TABLE_COLUMN_NAMES.ID} = ? - AND ${SEARCH_JOBS_TABLE_COLUMN_NAMES.STATUS} + WHERE ${SEARCH_JOBS_TABLE_COLUMN_NAMES.ID} = ? + AND ${SEARCH_JOBS_TABLE_COLUMN_NAMES.STATUS} IN (${SEARCH_JOB_STATUS.PENDING}, ${SEARCH_JOB_STATUS.RUNNING})`, jobId, );