-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat(gapic-ruby-generator): add logic to stop background process from toys gen on SIGINT #1036
base: main
Are you sure you want to change the base?
Conversation
… toys gen on SIGINT
6b5d94a
to
c727248
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is useful in cases where you have a broken logic in the generation step (e.g. referencing wrong variable in .erb
files). Otherwise, toys gen
on SIGINT cleans up correctly as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this technique should be really helpful. Just have some requests:
@@ -135,6 +135,17 @@ def run | |||
include :exec, e: true | |||
include :terminal | |||
|
|||
Signal.trap("SIGINT") do | |||
puts "SIGINT received. Cleaning up processes." | |||
toys_gen_pids = `ps aux`.each_line.filter_map { |line| line.split[1].to_i if line.match?(/ruby.*protoc/)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ruby.*protoc/
seems pretty lenient. Are you confident this won't be likely to hit false positives?
@@ -135,6 +135,17 @@ def run | |||
include :exec, e: true | |||
include :terminal | |||
|
|||
Signal.trap("SIGINT") do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put this in the implementation of toys gen
itself so it won't affect any other tools? (e.g. suppose I kick off a toys gen
in one terminal, so there are a bunch of generation processes running in the background, and then concurrently I run a totally unrelated toys tool in another terminal, and then interrupt it. Then this trap will kick in during the unrelated run, and clobber the generation.)
One way to do this is, rather than trapping the signal globally here, add an interrupt handler on the gen
tool implementation, which is located in shared/.toys.rb
. Use the on_interrupt
directive.
toys_gen_pids = `ps aux`.each_line.filter_map { |line| line.split[1].to_i if line.match?(/ruby.*protoc/)} | ||
puts "No toys gen processes running." if toys_gen_pids.empty? | ||
toys_gen_pids.each do |pid| | ||
puts "Terminating pid #{pid}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standard Ruby style is to indent 2 spaces.
Convenience tool to stop all processes spawned via
toys gen
(which may live in the background)