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

execute code with workhorse PID after the workhorse exits #2031

Open
backwardspy opened this issue Jan 31, 2024 · 1 comment
Open

execute code with workhorse PID after the workhorse exits #2031

backwardspy opened this issue Jan 31, 2024 · 1 comment

Comments

@backwardspy
Copy link

i am using rq together with prometheus client for metrics exposition. i have the prometheus client in multiprocess mode and i need to call a function (multiprocess.mark_process_dead(pid)) to let it know when a fork has completed so it can perform some necessary cleanup related to the given PID.

my first thought was a custom worker class, but i'm having trouble finding a convenient place to hook into the worker cleanup process that has access to the child's PID.

this is where i'm at now:

class CustomWorker(Worker):
    def execute_job(self, job, queue):
        super().execute_job(job, queue)
        mark_process_dead(self.horse_pid)

but i think that's too late in the process as self.horse_pid is already set back to 0 by that point.

i appreciate any advice you can offer, and thanks for the awesome project!

@selwin
Copy link
Collaborator

selwin commented Mar 3, 2024

Hey, sorry for the late reply. You're right, I don't see an obvious place to do this. There are a few places where horse_pid is set to 0 like here https://github.com/rq/rq/blob/master/rq/worker.py#L1335 but this would only work for successful job executions.

I think we'd need to modify the code base a little bit to store worker and horse information in Result object such that it's easily accessible.

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