samuelcolvin / arq

Fast job queuing and RPC in python with asyncio and redis.
https://arq-docs.helpmanual.io/
MIT License
1.98k stars 165 forks source link

Improves after_job_end hook #409

Closed AngellusMortis closed 2 months ago

AngellusMortis commented 11 months ago

Since finish_job can fail, I adjusted the after_job_end hook to always receive a copy of the the JobResult that would get written into redis.

I also updated all of the other places that recorded a failing job to call after_job_end as well and added a asyncio.shield to after_job_end as it is a great way to do something with the job result (like generate metrics for New Relic/Prometheus/etc.).

codecov[bot] commented 11 months ago

Codecov Report

Merging #409 (6859e3e) into main (ab2dda2) will decrease coverage by 0.09%. The diff coverage is 93.75%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #409 +/- ## ========================================== - Coverage 98.40% 98.31% -0.09% ========================================== Files 11 11 Lines 1063 1071 +8 Branches 200 201 +1 ========================================== + Hits 1046 1053 +7 Misses 8 8 - Partials 9 10 +1 ``` | [Files](https://app.codecov.io/gh/samuelcolvin/arq/pull/409?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Colvin) | Coverage Δ | | |---|---|---| | [arq/worker.py](https://app.codecov.io/gh/samuelcolvin/arq/pull/409?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Colvin#diff-YXJxL3dvcmtlci5weQ==) | `98.40% <93.75%> (-0.18%)` | :arrow_down: | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/samuelcolvin/arq/pull/409?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Colvin). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Colvin) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/samuelcolvin/arq/pull/409?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Colvin). Last update [ab2dda2...6859e3e](https://app.codecov.io/gh/samuelcolvin/arq/pull/409?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Colvin). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Colvin).
gerazenobi commented 4 months ago

@AngellusMortis hi there 👋

I am taking advantage of your deeper knowledge regarding this hook.

question: without this PR the hook after_job_end only works when there were no errors and jobs successfully finished? E.g. if the job raised an exception, the hook won't be called ?

If that is the case, would there be a work around using other hooks ?

Thanks in advance

AngellusMortis commented 2 months ago

I no longer care.