Skip to content
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

worker.py: Avoid letting a job get stuck if exception occurs #2

Open
wants to merge 1 commit into
base: master
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
37 changes: 25 additions & 12 deletions spark/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _run_job(self, job):
import traceback

tb = traceback.format_exc()
jlog.write(tb)
log.write(tb)
self._conn.send_job_status(job_id, JobStatus.REJECTED)
log.warning(tb)
log.info('Rejected job {}'.format(job_id))
Expand Down Expand Up @@ -184,19 +184,32 @@ def _request_job(self):
# there are no jobs available for us
return False

job_module = job_reply.get('module')
job_kind = job_reply.get('kind')
job_id = job_reply.get('uuid')

if job_kind in self._conf.accepted_job_kinds:
return self._run_job(job_reply)
else:
log.warning(
'Received job of type {0}::{1} which we can not handle.'.format(
job_module, job_kind
# Now that we've accepted a job, we just reply to the server, even if
# an exception occurs. If we don't, the job is stuck indefinitely and
# we will not be able to accept another.
try:
job_module = job_reply.get('module')
job_kind = job_reply.get('kind')
job_id = job_reply.get('uuid')

if job_kind in self._conf.accepted_job_kinds:
return self._run_job(job_reply)
else:
log.warning(
'Received job of type {0}::{1} which we can not handle.'.format(
job_module, job_kind
)
)
)
self._conn.send_job_status(job_id, JobStatus.REJECTED)
return False
except: # noqa: E722 pylint: disable=bare-except
import traceback

tb = traceback.format_exc()
jlog.write(tb)
self._conn.send_job_status(job_id, JobStatus.REJECTED)
log.warning(tb)
log.info('Rejected job {} due to exception'.format(job_id))
return False

def _update_archive_data(self) -> bool:
Expand Down
Loading