I'm doing some processing inside a job which ends up executing an external shell command. The command is executing a script that takes hours to finish.
Problem is that after I start the script using spawn and detach the script stops execution if I shut down the sidekiq job using a kill -15 signal. This behaviour is only occurring if the spawn
command is fired by sidekiq - not if I do it in irb and close the console. So somehow it's still bound to sidekiq it seems - but why and how to avoid it?.
test.sh
#!/bin/bash
for a in `seq 1000` ; do
echo "$a "
sleep 1
done
spawn_test_job.rb
module WorkerJobs
class SpawnTestJob < CountrySpecificWorker
sidekiq_options :queue => :my_jobs, :retry => false
def perform version
logfile = "/home/deployer/test_#{version}.log"
pid = spawn(
"cd /home/deployer &&
./test.sh
",
[:out, :err] => logfile
)
Process.detach(pid)
end
end
end
I enqueue the job WorkerJobs::SpawnTestJob.perform_async(1)
and if I tail the test_1.log
I can see my counter going on. However when I send sidekiq the kill -15 the counter stops and the script pid disappears.