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

Use function's keep_results configuration when storing failed jobs results #433

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Use closure variable for function, inline with existing code
joshwilson-dbx committed Feb 20, 2024
commit a06ea0439697cfbcdfe1a83a5250386d3e17cf5a
12 changes: 6 additions & 6 deletions arq/worker.py
Original file line number Diff line number Diff line change
@@ -483,10 +483,11 @@ async def run_job(self, job_id: str, score: int) -> None: # noqa: C901
abort_job = False

function_name, enqueue_time_ms = '<unknown>', 0
function: Optional[Union[Function, CronJob]] = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function: Optional[Union[Function, CronJob]] = None
function: Union[Function, CronJob, None] = None

args: Tuple[Any, ...] = ()
kwargs: Dict[Any, Any] = {}

async def job_failed(exc: BaseException, function: Optional[Union[Function, CronJob]]) -> None:
async def job_failed(exc: BaseException) -> None:
self.jobs_failed += 1
result_data_ = serialize_result(
function=function_name,
@@ -506,28 +507,27 @@ async def job_failed(exc: BaseException, function: Optional[Union[Function, Cron

if not v:
logger.warning('job %s expired', job_id)
return await job_failed(JobExecutionFailed('job expired'), None)
return await job_failed(JobExecutionFailed('job expired'))

try:
function_name, args, kwargs, enqueue_job_try, enqueue_time_ms = deserialize_job_raw(
v, deserializer=self.job_deserializer
)
except SerializationError as e:
logger.exception('deserializing job %s failed', job_id)
return await job_failed(e, None)
return await job_failed(e)

function: Optional[Union[Function, CronJob]] = None
with contextlib.suppress(KeyError):
function = self.functions[function_name]

if abort_job:
t = (timestamp_ms() - enqueue_time_ms) / 1000
logger.info('%6.2fs ⊘ %s:%s aborted before start', t, job_id, function_name)
return await job_failed(asyncio.CancelledError(), function)
return await job_failed(asyncio.CancelledError())

if function is None:
logger.warning('job %s, function %r not found', job_id, function_name)
return await job_failed(JobExecutionFailed(f'function {function_name!r} not found'), None)
return await job_failed(JobExecutionFailed(f'function {function_name!r} not found'))

if hasattr(function, 'next_run'):
# cron_job