Skip to content

Commit

Permalink
Use closure variable for function, inline with existing code
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwilson-dbx committed Feb 20, 2024
1 parent 07d2f4e commit a06ea04
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions arq/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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,
Expand All @@ -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
Expand Down

0 comments on commit a06ea04

Please sign in to comment.