python-arq/arq

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

frankie567 opened this issue · 1 comments

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:

https://github.com/samuelcolvin/arq/blob/9109c2e59d2b13fa59d246da03d19d7844a6fa19/arq/worker.py#L551-L560

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.

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"])