Stop report workers when parent times out

No need to keep running when nobody is collecting the result (yet).
This commit is contained in:
Maikel Linke
2023-01-11 20:45:45 +11:00
committed by Filipe
parent b19456535d
commit 26402397ea

View File

@@ -3,9 +3,16 @@
# Forks into a separate process to contain memory usage and timeout errors.
class JobProcessor
def self.perform_forked(job, *args)
fork do
# Reports should abort when puma threads are killed to avoid wasting
# resources. Nobody would be collecting the result. We still need to
# implement a way to email or download reports later.
timeout = ENV.fetch("RACK_TIMEOUT_WAIT_TIMEOUT", "30").to_i
child = fork do
Process.setproctitle("Job worker #{job.job_id}")
job.perform(*args)
Timeout.timeout(timeout) do
job.perform(*args)
end
# Exit is not a good idea within a Rails process but Rubocop doesn't know
# that we are in a forked process.
@@ -13,5 +20,9 @@ class JobProcessor
end
Process.waitall
ensure
# If this Puma thread is interrupted then we need to detach the child
# process to avoid it becoming a zombie.
Process.detach(child)
end
end