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

Add args and kwargs to job context for on_job_start/on_job_end hooks #415

Open
frankie567 opened this issue Sep 15, 2023 · 1 comment
Open

Comments

@frankie567
Copy link

on_job_start/on_job_end hooks are really useful for adding logs, setting up monitoring tasks, etc.

Currently, those hooks are passed a job context like this:

arq/arq/worker.py

Lines 551 to 560 in 9109c2e

job_ctx = {
'job_id': job_id,
'job_try': job_try,
'enqueue_time': ms_to_datetime(enqueue_time_ms),
'score': score,
}
ctx = {**self.ctx, **job_ctx}
if self.on_job_start:
await self.on_job_start(ctx)

It would be really interesting to also have the args and kwargs so we could log them or perhaps triggering specific behavior when detecting certain arguments.

This could look like this:

job_ctx = {
    'job_id': job_id,
    'job_try': job_try,
    'enqueue_time': ms_to_datetime(enqueue_time_ms),
    'score': score,
    'args': args,
    'kwargs': kwargs,
}

If that makes sense, I would happily open a PR with the required changes.

@frankie567 frankie567 changed the title Add args and kwargs to job context for on_job_start/on_job_end` hooks Add args and kwargs to job context for on_job_start/on_job_end hooks Sep 15, 2023
@KShah707
Copy link

As a manual workaround for now you can of course use

job = Job(ctx["job_id"], ctx["redis"])
job_def: JobDef = await job.info()

print(job_def["args"])
print(job_def["kwargs"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants