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

Ensure PIDFILE has pids of all running workers #1733

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

z0marlin
Copy link

@z0marlin z0marlin commented Nov 7, 2020

The workers now append to the PIDFILE instead of overwriting it.
Adding file locking to handle race conditions when multiple
workers are started using resque:workers.

To clear any older data in the specified PIDFILE, it is now truncated
once when the rake tasks resque:work and resque:workers are called.
Created a proxy task resque:run to achive this.

Fixes #1721

The workers now append to the PIDFILE instead of overwriting it.
Adding file locking to handle race conditions when multiple
workers are started using resque:workers.

To clear any older data in the specified PIDFILE, it is now truncated
once when the rake tasks resque:work and resque:workers are called.
Created a proxy task resque:run to achive this.

Fixes resque#1721
@z0marlin
Copy link
Author

ping

Copy link
Contributor

@iloveitaly iloveitaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help me understand the use case here more fully? I don't see why we have this task in the first place.

To get this merged:

  • Could you respond to the message about why we aren't building the PIDFILE logic into run?
  • Could you add a changelog entry?
  • Rebase on master so CI runs

Thanks for the contribution!

@@ -20,6 +20,15 @@
worker.work(ENV['INTERVAL'] || 5) # interval, will block
end

desc "Start a Resque worker"
task :work do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we defining a whole new task here instead of bundling this into run?

@@ -28,9 +37,13 @@
abort "set COUNT env var, e.g. $ COUNT=2 rake resque:workers"
end

if ENV['PIDFILE'] && File.file?(ENV['PIDFILE'])
File.truncate(ENV['PIDFILE'], 0)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workers should only be used in dev mode (I don't fully understand why we have this task in the first place). Are you using PIDFILE in devmode? What is your use case?

Rake::Task['resque:run'].reenable
Rake::Task['resque:run'].invoke
end

desc "Start multiple Resque workers. Should only be used in dev mode."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you understand the use case for this? Do you use this in production? Resque is designed around forking, so it seems strange that we support this. Also, shelling out to a rake task feels a bit dangerous to me for production-quality deployments.

@z0marlin
Copy link
Author

Could you help me understand the use case here more fully? I don't see why we have this task in the first place.

Hey @iloveitaly! The issue this change tries to fix is #1721. We have a requirement to automate starting and stopping of resque workers. When starting multiple workers in the background, to stop each of the workers, we need the PIDs of the workers and so it would be great to have all the PIDs in the PIDFILE.

This is quite an old PR. I'll need some time to look at the changes I made and then I can address the comments.

Thanks for reviewing the PR 😄

@iloveitaly
Copy link
Contributor

This is quite an old PR. I'll need some time to look at the changes I made and then I can address the comments.

@z0marlin sound great!

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

Successfully merging this pull request may close these issues.

PIDFILE contains only a single PID after starting multiple workers
2 participants