Skip to content

Commit 8f880f9

Browse files
committed
Make Attempt 1-indexed
1 parent dc1f04e commit 8f880f9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/mavedb/worker/jobs.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def enqueue_job_with_backoff(
6969
) -> tuple[Optional[str], bool, Any]:
7070
new_job_id = None
7171
backoff = None
72-
limit_reached = attempt >= BACKOFF_LIMIT
72+
limit_reached = attempt > BACKOFF_LIMIT
7373
if not limit_reached:
7474
limit_reached = True
7575
backoff = BACKOFF_IN_SECONDS * (2**attempt)
@@ -223,7 +223,7 @@ async def create_variants_for_score_set(
223223

224224

225225
async def map_variants_for_score_set(
226-
ctx: dict, correlation_id: str, score_set_urn: str, updater_id: int, attempt: int = 0
226+
ctx: dict, correlation_id: str, score_set_urn: str, updater_id: int, attempt: int = 1
227227
) -> dict:
228228
async with mapping_in_execution(redis=ctx["redis"], job_id=ctx["job_id"]):
229229
logging_context = {}
@@ -277,7 +277,7 @@ async def map_variants_for_score_set(
277277
db.rollback()
278278
score_set.mapping_state = MappingState.failed
279279
score_set.mapping_errors = {
280-
"error_message": f"Encountered an internal server error during mapping. Mapping will be automatically retried up to 5 times for this score set (attempt {attempt+1}/5)."
280+
"error_message": f"Encountered an internal server error during mapping. Mapping will be automatically retried up to 5 times for this score set (attempt {attempt}/5)."
281281
}
282282
db.add(score_set)
283283
db.commit()
@@ -343,7 +343,7 @@ async def map_variants_for_score_set(
343343
if not mapping_results["mapped_scores"]:
344344
# if there are no mapped scores, the score set failed to map.
345345
score_set.mapping_state = MappingState.failed
346-
score_set.mapping_errors = mapping_results["error_message"]
346+
score_set.mapping_errors = {"error_message": mapping_results["error_message"]}
347347
else:
348348
# TODO(VariantEffect/dcd-mapping2#2) after adding multi target mapping support:
349349
# this assumes single-target mapping, will need to be changed to support multi-target mapping
@@ -468,7 +468,7 @@ async def map_variants_for_score_set(
468468
db.rollback()
469469
score_set.mapping_state = MappingState.failed
470470
score_set.mapping_errors = {
471-
"error_message": f"Encountered an unexpected error while parsing mapped variants. Mapping will be automatically retried up to 5 times for this score set (attempt {attempt+1}/5)."
471+
"error_message": f"Encountered an unexpected error while parsing mapped variants. Mapping will be automatically retried up to 5 times for this score set (attempt {attempt}/5)."
472472
}
473473
db.add(score_set)
474474
db.commit()
@@ -538,7 +538,7 @@ async def map_variants_for_score_set(
538538

539539

540540
async def variant_mapper_manager(
541-
ctx: dict, correlation_id: str, score_set_urn: str, updater_id: int, attempt: int = 0
541+
ctx: dict, correlation_id: str, score_set_urn: str, updater_id: int, attempt: int = 1
542542
) -> dict:
543543
logging_context = {}
544544
mapping_job_id = None
@@ -551,8 +551,8 @@ async def variant_mapper_manager(
551551
logging_context["attempt"] = attempt
552552
logger.debug(msg="Variant mapping manager began execution", extra=logging_context)
553553

554-
queued_urn = await redis.rpop(MAPPING_QUEUE_NAME) # type: ignore
555554
queue_length = await redis.llen(MAPPING_QUEUE_NAME) # type: ignore
555+
queued_urn = await redis.rpop(MAPPING_QUEUE_NAME) # type: ignore
556556
logging_context["variant_mapping_queue_length"] = queue_length
557557

558558
# Setup the job id cache if it does not already exist.
@@ -617,6 +617,8 @@ async def variant_mapper_manager(
617617
)
618618

619619
if new_job:
620+
# Ensure this score set remains in the front of the queue.
621+
queued_urn = await redis.rpush(MAPPING_QUEUE_NAME, score_set_urn) # type: ignore
620622
new_job_id = new_job.job_id
621623

622624
logging_context["new_mapping_manager_job_id"] = new_job_id

0 commit comments

Comments
 (0)