Skip to content

fix(worker): retry heartbeat if JobDocument is not yet available #3205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions services/worker/src/worker/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,27 @@ def heartbeat(self) -> None:
worker_state = self.get_state()
if worker_state and worker_state["current_job_info"]:
job_id = worker_state["current_job_info"]["job_id"]
try:
Queue().heartbeat(job_id=job_id)
except Exception as error:
logging.warning(f"Heartbeat failed for job {job_id} (AfterJobPlan might be running): {error}")
# Don't stop since the AfterJobPlan may be running
# self.stop()
max_retries = 6
delay = 0.5 # seconds

for attempt in range(max_retries):
try:
Queue().heartbeat(job_id=job_id)
return # success
except Exception as error:
if "JobDocument matching query does not exist" in str(error):
if attempt < max_retries - 1:
logging.warning(
f"Heartbeat retry {attempt + 1}/{max_retries} for job {job_id} - waiting {delay}s: {error}"
)
time.sleep(delay)
else:
logging.error(f"Heartbeat failed after retries for job {job_id}: {error}")
else:
# Unrelated error, raise immediately
raise



def kill_zombies(self) -> None:
queue = Queue()
Expand Down